Repository navigation
gpui: count primitives into draw order instead of comparing them - #50
Merged
Merged
Conversation
A finished scene sorted each kind of primitive by sorting indices with a key read from the primitive on every comparison. Draw orders are few and small, so primitives other than sprites are now counted into their order's run (falling back to sorting packed keys when orders spread more than four times wider than the primitives are numerous), and left alone when already in order. Sprites sort one packed u128 of order, texture, tile and index. Both give exactly the order the old sort did.
trancong12102
added a commit
to aislopware/gpui-fast
that referenced
this pull request
Oct 9, 2026
Takes longbridge#50 (count primitives into draw order instead of comparing them) as history only: crates/gpui/src/fast/scene.rs keeps the fork's sort. The fork's 4105616 already packs every kind's keys into u64s and sorts them by an 11-bit LSD radix sort (a single counting pass while orderings stay under 2048, as longbridge#50 counts them), sprites included where longbridge#50 sorts u128 keys by comparison, skips kinds already in order, and reuses last frame's order when the keys repeat; fast::scene::primitive depends on the gathered flags it keeps. longbridge#50's tests cover its own functions and go with them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Scene::finishputs every kind of primitive in drawing order. It sorted anindex vector with
sort_unstable_by_key, reading each primitive's key out ofthe 112–168-byte primitive on every comparison, then gathered.
Draw orders are few and small (one past the greatest among the primitives a
primitive overlaps, or its layer's): a frame of
workspace-quoteshas 3324glyphs over 21 orders. So, in
fast/scene.rsonly:pass to count and one to place, and left alone when already in order.
Orders spread more than four times wider than the primitives are numerous
are sorted as packed
u64keys instead, so the counts stay short.u128of order, texture, tile and index, andare left alone when already in order.
Both give exactly the order the old sort did, so batches and drawing are
unchanged. No upstream file changes.
Correctness
cargo test -p gpui --features test-support --lib: 646 passed. New testscompare both sorts with a reference stable sort over random scenes (empty,
one item, in order, counted, spread too wide), check which way each case
was sorted and the threshold at its edge, and that the packed sprite key
keeps every bit of order, texture and tile.
gpui_perf --headless --verify: all 55 checks identical.script/check-upstream: 0 violations.Performance
The sort on real keys dumped from frames (single core, hot cache):
Headless, main-thread instructions per frame, retained views on, all 42
scenarios: every one lower, median −2.3%.
Real window (
--auto --only WorkspaceQuotes, 3 alternating runs of 600frames): instructions p50 16.5M → 16.1M with retention on, 22.7M → 22.3M
off. Wall-clock CPU time on this machine is noisier than the difference.
🤖 Generated with Claude Code