Skip to content

Live: a power or material edit writes only the light list's codes that changed (a frame 742 -> 13 ms with 275 flashing emitters) - #180

Merged
doodlewind merged 1 commit into
mainfrom
live-emitter-codes
Nov 20, 2026
Merged

doodlewind merged 1 commit into
mainfrom
live-emitter-codes

Conversation

@doodlewind

Copy link
Copy Markdown
Collaborator

A game that changes how bright its moving emitters are every frame (glowing bodies that flash when they bounce) spent about 470 ms of every frame in the commit. On each power or emission edit, write_emitters wrote the path code of every emitter outside the light tree's static part, one 4-byte write_buffer each: the list's records are 48 bytes apart, so Gather merged nothing, and 133 k moving emitter triangles were 133 k writes.

The loaded scene now keeps the codes it last wrote (LoadedScene::codes_sent) and writes only those that changed. A power edit leaves every code as it was, so it writes none.

  • A load or a rebuild makes a new loaded scene, so the cache starts empty and the first write sends every code, as before.
  • The list only grows in place. An emitter added in place has its record written with code 0 and is marked unsent, so its code is written after it.
  • Codes still change when the light tree's slot for emitters added in place is grown again (a scene with no moving emitters whose materials start emitting one after another). Those are written.

Measured

Apple M3 Max, "Torrent" (a test game, not in this PR): 500 bodies pouring down a slope, 275 of them glowing spheres and cubes (about 133 k moving emitter triangles), whose brightness the game changes on about 30 bodies a frame. 1280 × 720, render scale 1, lockstep, frames 60 to 240:

main 7d1dfc3 this branch
a frame 742 ms 13.1 ms
of it the commit 617 ms 1.5 ms
waiting for the emitter worker 115 ms 4.6 ms
GPU 12.7 ms 12.7 ms

The same with a material per body (emissiveIntensity instead of the object's power): 13.1 ms a frame, the same path.

Merge gate (R3: a perf claim)

  • npm run typecheck, npm test: pass.
  • cargo test --release: 206 passed. New: power_edits_keep_the_light_lists_codes, the GPU's light list against the codes after repeated power edits, a move, and two materials that start emitting one after the other (with moving emitters, with and without a light tree, and with still ones, whose tree slot regrows). A mutation that writes only codes never sent fails it (emitter 306's code). One run of the full suite failed the_light_list_holds_its_triangles and moved_instances_keep_their_motion with wgpu "buffer is invalid" validation errors; both pass alone and the suite passed on the rerun. cargo test --lib live fails a different few tests with the same errors on every run on main 7d1dfc3 too (parallel GPU tests).
  • test:render: main 261 pass / 3 unsupported, branch the same; nothing newly failing.
  • render-identity (main against branch, live tests included): 261 outputs, 238 byte-identical, 23 within their run-to-run spread, 0 changed.
  • Perf smoke (Bistro night, 0.5 floor): the first run failed still +1.9 / moving +2.4 / drive GPU p95 +2.9 ms, with drive GPU p50 −3.1. Rerun twice with the baseline re-measured: still / moving +0.10 / +0.05 and −0.57 / −0.08 ms; drive GPU p50 +3.10 (FAIL) and −2.99 ms. That p50 lands near 7 or near 10 ms on either build from run to run, while the drive's interval p50 / p95 stays within 0.4 ms in every run. The second rerun passed every line. Bistro makes no emission edits, so this code does not run there.
  • Bistro district, 0.5 floor, alternated main / branch / main / branch: GPU p50 12.3 / 12.1 / 12.0 / 12.1, p95 15.4 / 15.4 / 15.5 / 15.1 ms; interval p50 16.6 on all four.
  • Not run on Vulkan.

🤖 Generated with Claude Code

…t changed (a game flashing 300 moving emitters: 600 -> 11 ms a frame)

write_emitters rewrote the path code of every emitter outside the light tree's static part on each power or
emission edit, one 4-byte write_buffer each (the list's records are 48 bytes apart, so nothing merged): 133 k
moving emitter triangles cost a frame ~470 ms of commit. LoadedScene keeps the codes it last wrote
(codes_sent) and writes only those that changed; a load or a rebuild starts it empty, and emitters added in
place are written whole and then their codes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@doodlewind doodlewind changed the title Live: a power or material edit writes only the light list's codes that changed (600 -> 11 ms a frame with 300 flashing emitters) Live: a power or material edit writes only the light list's codes that changed (a frame 742 -> 13 ms with 275 flashing emitters) Nov 20, 2026
@doodlewind
doodlewind merged commit b63c6ab into main Nov 20, 2026
8 checks passed
@doodlewind
doodlewind deleted the live-emitter-codes branch November 20, 2026 22:10
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