Skip to content

perf(universe): sort body depth with a stable radix sort, the same order six times faster - #1059

Merged
alowpoly merged 2 commits into
mainfrom
perf/runtime-waste
Sep 30, 2026
Merged

alowpoly merged 2 commits into
mainfrom
perf/runtime-waste

Conversation

@alowpoly

Copy link
Copy Markdown
Contributor

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.

@alowpoly
alowpoly merged commit dcc94ce into main Sep 30, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant