pierrec / node-lz4

LZ4 fast compression algorithm for NodeJS
MIT License
438 stars 98 forks source link

Optimization for ArrayBuffer / DataView? Websockets. #46

Open vans163 opened 8 years ago

vans163 commented 8 years ago

On the browser side when you recv binary data off websockets you get it as an ArrayBuffer or Blob.

Right now you cannot pass that to new Buffer() constructor.

Instead you need to convert the buffer to a Uint8Array, this conversion is very expensive for some reason.

Then once you get your output, you need to convert it again to a Uint8Array (which is now 50-100x more expensive since its an uncompressed image) if you want to use it for something like canvas element; ctx.putImageData(imageData, 0, 0) for example.

Is there anyway to optimize this, perhaps allow Uint8Array to be passed directly instead of Buffer?

This is with large ArrayBuffers like around 2-5MB uncompressed.

The actual decompression takes about 10-20ms, then the array conversion back into a Uint8Array takes 20ms-80ms, I think it depends on memory pressure.

pierrec commented 7 years ago

Yes support for more (better) input types is required. Unfortunately, time is scarce :(. Pull requests anyone?