Repository navigation
perf: reuse the params and top scope tables across renders (0160) - #461
Merged
Merged
Conversation
The thread's RenderWorkspace lends each render its params map and top scope map and takes them back emptied, keeping their tables and nodes, so a steady render allocates nothing for them. many_tags: 15 -> 2 allocations per render, -5.1% instructions; every render with params: -2 allocations. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QFPahQrfHfhtFndTYZmPTe
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QFPahQrfHfhtFndTYZmPTe
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QFPahQrfHfhtFndTYZmPTe
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QFPahQrfHfhtFndTYZmPTe
rmorozov
marked this pull request as ready for review
October 11, 2026 13:43
rmorozov
pushed a commit
that referenced
this pull request
Oct 11, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMcWcpGwhiaEs33YjAgEV4
rmorozov
added a commit
that referenced
this pull request
Oct 11, 2026
Claude-Session: https://claude.ai/code/session_01KMcWcpGwhiaEs33YjAgEV4 Co-authored-by: Claude <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.
Requested by Ruslan · project thread
Before: every render built a fresh robin_hood map for its params (2 allocations, 558 B), and a template with many top-level
sets grew its top scope table from scratch each time. Render/many_tags spent 15 allocations, 82 KB and 6 rehashes (15% of its instructions) per render.After: the thread's
RenderWorkspacelends each render a params map and a top scope map and takes them back emptied.clear()keeps the bucket array and returns the nodes to the table's pool, so a steady render allocates nothing for either. many_tags drops to 2 allocations and 5.6 KB per render.How:
RenderWorkspace::LendMaps/ReturnMapsin stack order, so a render started inside another (a user callable rendering a template) is lent the next pair. Tables past 1024 buckets, and tables of renders nested deeper than four levels, are let go rather than kept on the thread.RenderContextgets a constructor that takes the top scope map (moved in only when it has a table) andTakeTopScope, called after a clean render; a failed render just drops the table.Measured (local callgrind, Release, against 1ca9c15): many_tags -4.6..-5.1% instructions (15 -> 2 allocs, peak 82,520 -> 5,632 B), substitute -13.2%, large_static -1.8%, others -0.7..0%, plain_text +1.5% (+15 instructions: the thread-local workspace lookup and lend). Every case with params: -2 allocations, -558 B. Details in docs/tasks/0160.
Roles: verifier (1 round, Sonnet). It found one blocking issue, clang-tidy
misc-include-cleaneron changed lines, which was already fixed in the second commit; sanitizers (clang ASan+UBSan), nested/throwing renders, threads and wide templates were clean. Its non-blocking note on deep nested renders holding tables is addressed in the third commit. Red pushes in CI: none yet.🤖 Generated with Claude Code
https://claude.ai/code/session_01QFPahQrfHfhtFndTYZmPTe
Generated by Claude Code