You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made a simple WASM image filter, I tested it on the browser, compare it to pure js version and tried wasmer to run the filter.
There was a huge bottleneck when moving the large data to wasm memory. several seconds instead of milliseconds.
more over assigning multidimensional data was even slower (30x) slower.
Proposed solution
implement faster assign to a memory slice
Make slice assign on np.ndarray(A, dtype=np.uint8) and array.array('B') as fast as bytearray
if multidimensional make unwinding/flattening outside python, move it to the c implementation
class Uint8Array(object)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
this function seems to walk into the slice items one by one
Iterating over the WxHxC multidimensional array in python is a huge wast of time
As the only reason for moving to WASM is to do the hot/active loop.
Additional context
importnumpyasnpimportarrayfromwasmerimportStore, Module, Instance, Memory, MemoryTypefromPILimportImagememory=Memory(Store(), MemoryType(minimum=200))
u8buf=memory.uint8_view(100)
a3d=np.zeros((1920, 1080,4), dtype=np.uint8)
flat=a3d.flatten()
flata=array.array('B', flat)
img=Image.fromarray(a3d, 'RGBA')
pil_a3d=img.getdata()
offset=200size=1920*1080*4u8buf[offset:offset+size]=bytearray(flat) # <------ `bytearray` type is fast but not fast enoughu8buf[offset:offset+size]=flat# <-------- `np.ndarray` is slowu8buf[offset:offset+size]=flata# <-------- `array.array` is slowu8buf[offset:offset+size]=a3d# <-------- multidimensional `np.ndarray` is impossibleu8buf[offset:offset+size]=pil_a3d# <-------- `PIL img.getdata()` is impossible
note things I marked as slow are at least 30x times slower.
muayyad-alsadi
changed the title
[RFE] multidimensional memory buffer assign is too slow
[RFE] passing data in is too slow via slice assign on memory buffer
Mar 2, 2023
Motivation
I made a simple
WASM
image filter, I tested it on the browser, compare it to pure js version and tried wasmer to run the filter.There was a huge bottleneck when moving the large data to
wasm
memory. several seconds instead of milliseconds.more over assigning multidimensional data was even slower (30x) slower.
Proposed solution
np.ndarray(A, dtype=np.uint8)
andarray.array('B')
as fast asbytearray
this function seems to walk into the slice items one by one
Alternatives
Iterating over the WxHxC multidimensional array in python is a huge wast of time
As the only reason for moving to WASM is to do the hot/active loop.
Additional context
NOTE: I'm using Fedora 36, Python 3.10.9, python wasmer 1.1.0, wasmer-compiler-singlepass 1.1.0
The text was updated successfully, but these errors were encountered: