reimplement imageToByteArray in wasm #50
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This library is doing some bitmap manipulation to cater to the different flip/rotation required for some models, and the colour space both over the wire, and being provided by user code.
Doing this in javascript is not particularly efficient.
This re-implements that logic in rust, compiled to wasm. By doing this, we get a ~50% speed boost on this block of code.
On my i7 laptop, it improves to 40ms from 90ms for 1000 images.
On a pi zero w2, it improves to 420ms from 880ms for 1000 images.
This improvement on the pi makes the extra complexity of this feel worthwhile. This is a rather synthetic test, but even doing kust a full panel draw of an xl from the pi saves ~15ms (I adjusted the test to verify).
For compatability, I think we should support both wasm and native js for this code. If for some reason wasm is unavailable (perhaps running in a browser and the wasm file has not been provided), then we can fallback to javascript. The performance improvement is not proven to be significant enough to justify requiring wasm.
I dont expect this to result in more than a couple of percent improvement, I shall do some more testing once this is closer to being usable