perf(universe): sort body depth with a stable radix sort, the same order six times faster - #1059
Merged
Merged
Conversation
…ks in a typed array; the same order six times faster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Change
Every frame the view turns, the universe re-sorted all 3,631 bodies by depth with a comparator and re-ranked them in a map. It was the top script cost on every page. A stable radix sort on the depth's bits now gives the same order, with ranks kept in a typed array.
Evidence and limits
Proves the change: main's and the new depth order, cut from their source and run on the prepared world bodies with ties and -0 added, give identical ranks and z-indices across 2,400 random orientations. One update takes 0.10 ms instead of 0.61 ms. In the Earth and Milky Way replay profiles, the depth order falls from 3.8% of samples to 0.6%.
Clean: renderer universe and node tests, runtime-package tests, renderer typecheck.