-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BatchedMesh: Add setCustomSort function, hybrid radix sort implementation to examples #27213
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
I haven't delved much into the implementation yet, but my first thought is that maybe garbage collection is playing a role here. |
That was my first thought, too - I had missed that an array was getting created internally on every call when I thought was cached so that was likely it. Just pushed the fix. |
I get similar sorting times, but slightly better overall performance ( ~40% )
I believe radix-sort can be a beneficial addition to three, but it's important to inform the users of the restrictions, as it is a less general function than There are currently two important restrictions:
The first restriction is not bad as it might seem,
edit: positive floating point values should be bit-cast, instead of normalizd - otherwise truncated values produce incorrect ties |
TBH, I would prefer to keep this outside of the core since Could you add something like |
It's a pretty significant improvement but admittedly likely only really relevant for particularly complex cases. How would you feel about something like a |
So you mean moving |
I've adjusted the PR to move the radix sort function into a "SortUtils.js" example file, added a "customSort" function to BatchedMesh, and updated the example to include a "useCustomSort" function. |
…tion to examples (mrdoob#27213) * Add radix sort to batched mesh * Fix options generation * Add custom sort function, separate radix sort function to examples * Adjust custom sort application * revert count and position in demo * Update demo * Add docs * Comments
Related issue: #22376, #27202 (comment)
Description
For the sake of discussion here's a draft PR that shows the performance improvements using the suggested sort implementation from #27202 (comment). If you want to try it you can run the batched example page and toggle the "useRadix" option to see the difference. The sort time is logged in the console.
Performance
Overall it looks like the new sort is providing roughly a 10x improvement in sort time over the native sort information. The drawback of the sort is that it requires more memory to store a temporary array:
There seem to be occasional dips in fps with the hybrid sort to ~89fps on my machine but I'm not sure why.
Overall it's a meaningful improvement in complex cases. I'm not sure what opinions of others are on whether this should be included in three, though.
cc @Mugen87 @mrdoob @sciecode