Optimize floatVectorToFloatArray for performance improvements - #76
Conversation
Optimize floatVectorToFloatArray for improved performance
|
Hi, @drumath2237. This performance issue bubbled up for us with CesiumJS. It would be great to know when you're planning on performing the next release for To make it clear, my intent is not to rush you but just to understand so we can plan appropriately. Thank you! |
|
Thank you for your contribution! |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the floatVectorToFloatArray function to improve performance when handling large data volumes. The changes involve using HEAPF32.slice for more direct memory copying from the WASM heap and employing a for loop for conditional data processing, which is more efficient than the previous .map implementation. The enhancementFunc is also now optional, avoiding unnecessary work. After a thorough review, I have not identified any issues or further improvement opportunities in the submitted changes.
drumath2237
left a comment
There was a problem hiding this comment.
LGTM!
When I tested it locally with racoonfamily.spz, the decoding speed improved by about 100–300 ms. Thank you so much!
|
I have just published version 0.3.1 of spz-loader/core. https://github.com/drumath2237/spz-loader/releases/tag/v0.3.1 |
This changes the
floatVectorToFloatArrayfunction used heavily during loads to use a faster method for copying the memory from the emscripten context to JS context. This was impacting us during loads of large scenes in CesiumJS, and has resulted in about a full second faster load time with the Microsoft campus dataset.Our PR in our fork of this repo has some additional instructions and info on how we tested this out: CesiumGS#3
Key changes
sliceto copy data from the WASM heap, which is more efficient and avoids mapping over the buffer by default.mapto afor-loop. For small datasets, this doesn't matter, but when simultaneously loading multiple datasets, each with >4 million Gaussians, the additional overhead ofmapquickly becomes costly.enhancementFuncparameter is now optional and only applied if defined, reducing unnecessary processing for the default case.