You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(renderer): reduce CPU work for image table bindings #359
area: executeCommand processor and the Resolve, Execute and Record stages: CPU cost per drawhelp wantedExtra attention is neededperfSpeed: frames per second, CPU or GPU time, stutters
Profile the CPU work to prepare, validate, rebind and commit image tables on kytyGpuExecute. Start with PrepareBindings, RebindImages and CommitBindings. This is a focused task under #55 and #168.
In four warm-cache 1080p frames on Linux/NVIDIA, the main executor used 10.14 CPU seconds over 12.09 seconds of elapsed time. Sampled stacks repeatedly found table materialization and binding work. The frame times include other work and should not be read as the exclusive cost of these functions.
Acceptance
Report per-frame CPU time by phase, table sizes, and reuse and invalidation rates.
Reduce repeated scans or rebuilds for unchanged tables. Exercise both repeated aliases and mostly unique entries.
Verify that descriptor contents, binding order, and the handling of mutations and resource lifetime match the baseline. Report median and tail timings for the same warm-cache workload before and after.
Is the original warm-cache capture available as a per-frame CPU breakdown for PrepareBindings, RebindImages, and CommitBindings? That would help identify which phase to tackle first; the executor total can’t distinguish binding costs from other work.
I recovered the exact four consecutive warm-cache 1080p frames from the issue. Here is the main executor thread breakdown on Linux/NVIDIA. CPU times for the three phases are inclusive sampling estimates. The capture contains 1,014 CPU-clock samples at 100 Hz and 127 stack samples.
Frame interval
Wall time (s)
Executor CPU (s)
PrepareBindings CPU (s)
RebindImages CPU (s)
CommitBindings CPU (s)
1
2.684
2.45
0.459
0.610
0.547
2
2.916
2.55
0.604
0.427
0.508
3
3.032
2.40
0.498
0.408
0.409
4
3.454
2.74
0.813
0.335
0.568
Whole window
12.087
10.14
2.369
1.776
2.036
The phase timings include callees and are approximate. They cover the main executor thread only. RebindReusedTables is inside RebindImages and accounted for an estimated 0.895 s across the window.
In a 10-second counter window from the same run, 2,510 of 2,710 table preparations reused a finished binding state (92.6%). All 200 rebuilds encountered an unfinished or absent binding state. All 504 table-resolution lookups hit, with zero resolution evictions, generation changes or generation-related rebuilds. The renderer separately counted 221 binding-state retirements. These counters cover a different time window from the four frames above. They do not establish a one-to-one match between retirements and rebuilds.
Brainrot has since gained parallel validation of large image tables in 64e36f283145. The remaining experiment is to reuse unchanged slot mappings when the binding state needs to be reconstructed, while still revalidating each distinct resource in its original order.
Thanks for recovering the per-frame baseline. For the slot-mapping experiment, can you report total slots and distinct resources per rebuilt table? That will show how much work mapping reuse can avoid for alias-heavy versus mostly unique tables. Use a baseline that already includes parallel validation so the before/after comparison isolates mapping reuse.
A candidate on the current Brainrot base reuses slot mappings when an immutable image-table snapshot is seen again during reconstruction. Adjacent slots targeting the same resolved element share one visit. Padding uses the existing slot-zero null descriptor. Each distinct element still goes through the existing validation and bind path in first-occurrence order. The cached mapping is invalidated when a slot memo changes or the resolution is retired.
The original capture's shader store contains 2,388 table-bearing module records. The total descriptor capacity per stored stage ranges from 32,768 to 196,608, across one or more table ranges. These are capacities from the stored layouts. Runtime table visits and the number of distinct textures per frame are separate measurements.
The CPU benchmark uses the production reconstruction loops with a modeled resolver. Timings below are for one synthetic table reconstruction in microseconds, with 40 timed repetitions per configuration. The results are the median of five runs for each percentile.
Configuration
Baseline p50
Candidate p50
Baseline p95
Candidate p95
32,768 slots, 63 aliases then one distinct row
161.73
39.75
172.53
43.44
65,536 slots, same alias pattern
322.62
74.97
345.05
82.98
65,536 slots, 8,192 present rows and a null tail
366.16
126.34
380.04
133.80
65,536 mostly unique slots, two rows swapped and a new snapshot identity each time
781.00
683.99
792.38
693.98
All 1,001 differential comparisons passed with ASan and UBSan. The comparisons cover descriptor values, slot order, aliasing across roots, mutations, unrecognized snapshot identities, and resolution retirement. Three targeted tests passed on both builds on Linux/NVIDIA with the Vulkan validation layer loaded and no VUID errors. The timings above are scoped to the reconstruction loop. The same-scene frame A/B is still pending.
Thanks for the differential and Vulkan validation results. The reconstruction benchmark shows lower p95 even in the mostly unique case, but it doesn’t establish a frame-level gain yet.
For the pending same-scene warm-cache A/B, use the same base with parallel validation in both builds and report per-frame CPU time for all three phases, plus median and tail frame timings. In that same capture, record actual slot and distinct-resource counts per rebuilt table, along with mapping reuse and invalidation rates. That will show how often the workload gets the alias-heavy benefit measured in the benchmark.
Runtime follow-up on the published Brainrot base 64e36f283145, at 1080p on Linux/NVIDIA. In one window of eight consecutive frame intervals with zero logged pipeline compile events, the baseline wall median was 2.981 s and p95 was 3.418 s (nearest rank). The main executor used 23.41 CPU seconds. Inclusive sampling estimates for the window were 8.274 s in PrepareBindings, 3.124 s in RebindImages, and 7.403 s in CommitBindings.
A separate 10-second counter window in that run had 1,332 table preparations, including 78 state reuses (5.9%) and 1,254 rebuilds. Resolution-cache lookups hit 3,312 out of 3,312 times, with zero resolution evictions. The renderer counted 1,162 binding-state retirements. This is evidence of binding-state churn on the current base as well as in the original capture.
The same-scene candidate frame comparison remains open. The system memory-pressure service stopped the candidate before it reached the baseline window. The retry with a shared, refreshed cache seed hit further runtime pipeline compiles and a memory-pressure stop on the baseline. See #338 for the corroborating pipeline-cache observation. The CPU reconstruction A/B and the descriptor correctness checks above are complete.
Thanks for checking the current base. The counters show that binding states are often rebuilt even when resolution lookups hit, which supports testing slot-mapping reuse. The reconstruction benchmark and correctness checks are complete, but the interrupted runs don’t establish a frame-level gain.
Could you capture a shorter matched, compile-free window that both builds can reach before memory pressure stops either run? If so, report the number of frames and the slowest frame alongside the median; with only a few frames, p95 is effectively the maximum.
I measured a second change against the first reconstruction candidate. Temporary rebind metadata now groups the view, descriptor reference, root and version in one record. The reference points into the immutable table snapshot used by the draw. The persistent binding state still owns its descriptor values.
The paired CPU benchmark uses the production reconstruction loops with a modeled resolver. Each configuration has five runs of 40 timed repetitions. Values below are in microseconds and use the median of the per-run percentiles.
65,536-slot configuration
Previous p50
Current p50
Previous p95
Current p95
Mostly unique entries, two rows swapped per reconstruction
692.9
563.3
712.6
584.2
Stable snapshot, runs of 63 aliases followed by a distinct entry
76.2
71.2
82.0
77.8
Stable snapshot, all entries alias the null element
40.6
40.6
46.1
45.3
All 1,001 differential comparisons passed under ASan and UBSan, including descriptor values, binding order, aliased roots and mutations. Three targeted tests passed on both builds on Linux/NVIDIA with the Vulkan validation layer loaded and zero VUID errors. The same-scene frame comparison remains open.
The paired reconstruction benchmark shows an 18% drop in p95 for mostly unique tables versus the first candidate. The reported sanitizer and Vulkan checks are encouraging. With the new descriptor reference, can you confirm that the draw keeps the snapshot alive through the last temporary metadata read, including when the resolution is retired? The matched frame A/B is still needed to establish a frame-level gain.
area: executeCommand processor and the Resolve, Execute and Record stages: CPU cost per drawhelp wantedExtra attention is neededperfSpeed: frames per second, CPU or GPU time, stutters
Activity
github-actions commentedon Nov 27, 2026
Is the original warm-cache capture available as a per-frame CPU breakdown for
PrepareBindings,RebindImages, andCommitBindings? That would help identify which phase to tackle first; the executor total can’t distinguish binding costs from other work.simnJS commentedon Nov 27, 2026
I claim it
github-actions commentedon Nov 27, 2026
Thanks for taking this on.
simnJS commentedon Nov 27, 2026
I recovered the exact four consecutive warm-cache 1080p frames from the issue. Here is the main executor thread breakdown on Linux/NVIDIA. CPU times for the three phases are inclusive sampling estimates. The capture contains 1,014 CPU-clock samples at 100 Hz and 127 stack samples.
The phase timings include callees and are approximate. They cover the main executor thread only.
RebindReusedTablesis insideRebindImagesand accounted for an estimated 0.895 s across the window.In a 10-second counter window from the same run, 2,510 of 2,710 table preparations reused a finished binding state (92.6%). All 200 rebuilds encountered an unfinished or absent binding state. All 504 table-resolution lookups hit, with zero resolution evictions, generation changes or generation-related rebuilds. The renderer separately counted 221 binding-state retirements. These counters cover a different time window from the four frames above. They do not establish a one-to-one match between retirements and rebuilds.
Brainrot has since gained parallel validation of large image tables in
64e36f283145. The remaining experiment is to reuse unchanged slot mappings when the binding state needs to be reconstructed, while still revalidating each distinct resource in its original order.github-actions commentedon Nov 27, 2026
Thanks for recovering the per-frame baseline. For the slot-mapping experiment, can you report total slots and distinct resources per rebuilt table? That will show how much work mapping reuse can avoid for alias-heavy versus mostly unique tables. Use a baseline that already includes parallel validation so the before/after comparison isolates mapping reuse.
simnJS commentedon Nov 27, 2026
A candidate on the current Brainrot base reuses slot mappings when an immutable image-table snapshot is seen again during reconstruction. Adjacent slots targeting the same resolved element share one visit. Padding uses the existing slot-zero null descriptor. Each distinct element still goes through the existing validation and bind path in first-occurrence order. The cached mapping is invalidated when a slot memo changes or the resolution is retired.
The original capture's shader store contains 2,388 table-bearing module records. The total descriptor capacity per stored stage ranges from 32,768 to 196,608, across one or more table ranges. These are capacities from the stored layouts. Runtime table visits and the number of distinct textures per frame are separate measurements.
The CPU benchmark uses the production reconstruction loops with a modeled resolver. Timings below are for one synthetic table reconstruction in microseconds, with 40 timed repetitions per configuration. The results are the median of five runs for each percentile.
All 1,001 differential comparisons passed with ASan and UBSan. The comparisons cover descriptor values, slot order, aliasing across roots, mutations, unrecognized snapshot identities, and resolution retirement. Three targeted tests passed on both builds on Linux/NVIDIA with the Vulkan validation layer loaded and no VUID errors. The timings above are scoped to the reconstruction loop. The same-scene frame A/B is still pending.
github-actions commentedon Nov 27, 2026
Thanks for the differential and Vulkan validation results. The reconstruction benchmark shows lower p95 even in the mostly unique case, but it doesn’t establish a frame-level gain yet.
For the pending same-scene warm-cache A/B, use the same base with parallel validation in both builds and report per-frame CPU time for all three phases, plus median and tail frame timings. In that same capture, record actual slot and distinct-resource counts per rebuilt table, along with mapping reuse and invalidation rates. That will show how often the workload gets the alias-heavy benefit measured in the benchmark.
simnJS commentedon Nov 27, 2026
Runtime follow-up on the published Brainrot base
64e36f283145, at 1080p on Linux/NVIDIA. In one window of eight consecutive frame intervals with zero logged pipeline compile events, the baseline wall median was 2.981 s and p95 was 3.418 s (nearest rank). The main executor used 23.41 CPU seconds. Inclusive sampling estimates for the window were 8.274 s inPrepareBindings, 3.124 s inRebindImages, and 7.403 s inCommitBindings.A separate 10-second counter window in that run had 1,332 table preparations, including 78 state reuses (5.9%) and 1,254 rebuilds. Resolution-cache lookups hit 3,312 out of 3,312 times, with zero resolution evictions. The renderer counted 1,162 binding-state retirements. This is evidence of binding-state churn on the current base as well as in the original capture.
The same-scene candidate frame comparison remains open. The system memory-pressure service stopped the candidate before it reached the baseline window. The retry with a shared, refreshed cache seed hit further runtime pipeline compiles and a memory-pressure stop on the baseline. See #338 for the corroborating pipeline-cache observation. The CPU reconstruction A/B and the descriptor correctness checks above are complete.
github-actions commentedon Nov 27, 2026
Thanks for checking the current base. The counters show that binding states are often rebuilt even when resolution lookups hit, which supports testing slot-mapping reuse. The reconstruction benchmark and correctness checks are complete, but the interrupted runs don’t establish a frame-level gain.
Could you capture a shorter matched, compile-free window that both builds can reach before memory pressure stops either run? If so, report the number of frames and the slowest frame alongside the median; with only a few frames, p95 is effectively the maximum.
simnJS commentedon Nov 27, 2026
I measured a second change against the first reconstruction candidate. Temporary rebind metadata now groups the view, descriptor reference, root and version in one record. The reference points into the immutable table snapshot used by the draw. The persistent binding state still owns its descriptor values.
The paired CPU benchmark uses the production reconstruction loops with a modeled resolver. Each configuration has five runs of 40 timed repetitions. Values below are in microseconds and use the median of the per-run percentiles.
All 1,001 differential comparisons passed under ASan and UBSan, including descriptor values, binding order, aliased roots and mutations. Three targeted tests passed on both builds on Linux/NVIDIA with the Vulkan validation layer loaded and zero VUID errors. The same-scene frame comparison remains open.
github-actions commentedon Nov 27, 2026
The paired reconstruction benchmark shows an 18% drop in p95 for mostly unique tables versus the first candidate. The reported sanitizer and Vulkan checks are encouraging. With the new descriptor reference, can you confirm that the draw keeps the snapshot alive through the last temporary metadata read, including when the resolution is retired? The matched frame A/B is still needed to establish a frame-level gain.