Repository navigation
perf: render a loop's simple="vue" rows in one render-queue task (native render, level C1) - #267
Merged
Merged
Conversation
JuroOravec
force-pushed
the
perf/native-render-run-tasks
branch
from
October 23, 2026 09:44
f0fbef6 to
d3aaea7
Compare
JuroOravec
force-pushed
the
perf/native-render-run-tasks
branch
from
October 23, 2026 10:09
d3aaea7 to
ef6c9cf
Compare
…ive render level C1) A c-for loop over a simple='vue' component now records its rows in one _DeferredRun, with one _DeferredRunRow at each row's position in the parts list, instead of building a CitryElement and a DeferredComponent per row. The render queue gives rows of one run that sit next to each other one task (_RunTask), which renders them in the order their own tasks would. A row that calls child components or takes the ordinary component path stops the task, and the queue renders that row's work with a task for the remaining rows under it; a row that is too deep or whose position is gone raises the error its own task raises. Output bytes and the order of every callback and hook are unchanged; the order records from #263 pass unchanged on both render paths. This level is Python only and runs on every interpreter, on both the Rust and the Python path. - citry_render.py: _DeferredRun and _DeferredRunRow (one object per row position, so the queue finds rows by identity when a hook reorders, drops or repeats them; the row's DeferredComponent is built once). - nodes/__init__.py: ComponentNode.render ends in _finish_render; _render_run_row; ForNode._call_run_class and _render_call_run. - component_render.py: _simple_vue_record, shared by _render_simple_vue_leaf and the run task's _run_row; _run_rows, _place_run_part, _RunTask and the settle loop's run branch with its four exits; place_child shared with the per-row task; the scan groups adjacent rows; _contains_deferred and _nesting_depth_error_for. - _vue/capture.py: a leftover row is an unresolved part. - Tests: test_call_run_tasks.py (the board spy on both paths, both position-gone exits, hook edits and a re-printed list compared with one task per row in the same process, rows that change later rows, the three public routes that see unplaced rows). - Docs: native_render.md section 3 and C1's error modes; component_rendering.md, component_rendering_defer.md, component_on_render.md, vue_optimization_rollout.md, agent INDEX, and a ledger row with the timing pending. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
perf/native-render-run-tasks
branch
from
October 23, 2026 10:46
ef6c9cf to
1851f97
Compare
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 this changes
Today a
<c-for>loop over asimple = "vue"component gives the render queue one task per row. While the parent's template runs, the loop builds aCitryElementand aDeferredComponentfor every row. The queue then pops each row's task, checks the depth, sets the row's execution scope, makes the row's admission checks, runs its callbacks and puts its record in place.With this PR, the queue renders such a loop's rows in one task (
_RunTask), in the same order:ForNode._call_run_classchecks that the loop is a call run ofsimple = "vue"rows: the checksForNode.renderalready makes after the loop, plus three more: the class issimple = "vue", the inputs are plain, and the call's metadata does not target an element.ForNode._render_call_runmakes each row's template steps in their usual order, but records the row's kwargs and call metadata in one_DeferredRuninstead of building its element. Each row's position in the parts list gets its own small_DeferredRunRow, so the list still has one object per row._run_rowsrenders the rows in order: for each row the depth check, the execution scope, the admission checks that can change between rows, then the same steps as_render_simple_vue_leaf. Both now call one shared function,_simple_vue_record, which also makes level A's Rust row read when the Rust path is on.This level is Python only. It runs on every interpreter, on both the Rust path and the Python path, so PyPy, Pyodide and free-threaded builds use it too and Citry keeps one render queue. Output bytes and the order of every user callback and extension hook stay the same: the order records from #263 (
test_call_run_order.py) pass unchanged on both paths.Measured
Release wheels, Python 3.12, 10 alternating fresh-process pairs of 11 renders of the benchmark board; mean per process.
CITRY_NATIVE_RENDER=0on both)main-> this PR, Python path (the whole stack so far)main-> this PR, Python pathOn the Rust path C1 is a small gain at 1,400 rows and level at 140. On the Python path, which PyPy, Pyodide and free-threaded builds run, it gains at 1,400 rows and costs about 0.17 ms (1.2%) at 140 rows, most likely the one small object per row added by the review fix. The plan's bar for the Python path was "not slower than
main"; at 140 rows it misses that by about 1%, so this is flagged for the maintainer's decision. C1 ships mainly as the base that level C2 needs.Notable implementation choices
on_slot_rendered) that reorders or drops the unplaced rows, or a slot render printed again after some rows were placed, then renders different rows, or the same rows in a different order. With one_DeferredRunRowper position, the queue finds each row by identity, as it finds aDeferredComponent, and both cases match one task per row exactly._render_simple_vue_leafinto the run task. Here both call_simple_vue_record, so the steps after the admission checks exist once._render_simple_vue_leafgains one function call per row it renders.ComponentNode.rendersplit. It now ends in_finish_render, so a row that leaves its run finishes as an ordinary call without resolving its inputs or looking up its class twice. This adds one method call to every component call.place_child, used by the per-row task and the run task's ordinary-path exit.row_runs.rs,_RowRunPlan) and the Python helper table it read, theCITRY_RESEARCH_RUN_TASKSswitch and the counters.Accepted differences (none changes output)
_run_rowsand_run_rowin its traceback, where a row with its own task shows_render_simple_vue_leaf. The innermost frame, where user code raised, is the same._call_run_classreads the class'ssimple,transparentand selector flags before the loop runs. Only a user metaclass with a read hook could see this.CitryRender.partscan hold a_DeferredRunRowat a row's position where it held aDeferredComponent, until the queue places the rows. Neither class is exported fromcitry. Three public routes can hand user code such a render: calling a template-defined slot, theon_slot_renderedhook, and a nested template passed as a kwarg. In each, the list has one object per row andstr()raises the error an unplaced deferred component raises; a test covers each route.on_renderandon_component_renderedsee a render only after its rows are placed.Tests
tests/test_call_run_tasks.py(31 cases, under a second on four workers). Every case but the last runs on both paths:RuntimeErrorleaves the render past theon_renderboundary, after the same callbacks;on_slot_renderedhook that reverses, drops or repeats the unplaced rows; a rows list printed again after its first row; a row that makes the class fail admission; an ordinary-path row that raises under a swallowing boundary; a class that becomes a dynamic selector between rows; and a parts list edited before its rows are placed;tests/test_call_run_order.py(91 cases) passes unchanged on both paths. It covers the faults,KeyboardInterrupt, the depth limit with and without a swallowing boundary, rows that change engine or class state for later rows, child calls, slot fills, the nested template printed twice, tracing and two threads.Review
An independent reviewer (high effort) checked callback order, exception paths, re-entrancy and threads against a snapshot of #266. It found two major problems, both from the research design of one shared object at every row position: a hook that edits the unplaced rows, and a list scanned again after some rows were placed (a different callback order). Both are fixed by one object per row and locked by tests that compare with one task per row. It also found four inaccurate statements in the design doc, all corrected, and branches no test reached; tests now cover the ordinary-path error under a boundary and the selector flip. Four guards stay without a test because no page reaches them:
simplechanging between rows (the class's metaclass refuses that change), the registry identity check in a run, the root-call check, and a row seeing a different execution frame during the walk. A separate prose pass found about 30 items (four of them wrong statements); all were applied except shortening two existing headings this PR did not write.The same reviewer then re-checked the fix against the #266 snapshot: 88 cases per path in which an
on_slot_renderedhook edits the unplaced rows in 11 ways (reverse, delete, repeat, rotate, an empty string between rows, a row moved to another list, two runs interleaved, and others), each with one or two loops, ordinary-path rows and rows with a child. Bytes and callback order matched in every case. It found no blocker or major problem; its one test nit is applied. A second prose pass found one accidentally dropped paragraph (the level B1 test bullet innative_render.md, restored), two missing rows in the C1 error table (added) and smaller wording items, all applied.Gates
scripts/check.py --profile fast --reporter agent, on the commit):"status": "PASSED", every phase passed.--platform linux(593 source files).pytest -m "not e2e" -n 4 --python-render-path): 12,824 passed, 145 skipped, 1 xfailed.--cov, run locally on Python 3.14): 89.53%, against a ratchet of 88.5 (89.52% on perf: record each call run of Rust-read rows with one Rust object (native render, level B1) #266). The new lines no test reaches are guards no page can reach: thesimplecheck and the registry and root-call checks in_run_row, theAssertionErrorafter the position-gone raise, a row seeing a different execution frame during the walk, and three early returns in_call_run_classthat the template parser or the plain-input check already rules out.Cross-binding list
citry_render.py,nodes/__init__.py,component_render.py,_vue/capture.py, and two comments inserialize.py.LangImplchange, and no new required name innative_render._REQUIRED_NAMES.docs/design/native_render.md(new section 3, C1's error modes and accepted differences, code map, tests),docs/design/component_rendering.md,component_rendering_defer.mdandcomponent_on_render.md(the run task in the render queue),vue_optimization_rollout.md(prior art),docs/agent/INDEX.md, and a ledger row inperformance_architecture_experiments.mdmarked "timing pending".Base
Rebased onto
mainafter #263, #265 and #266 merged; the content is unchanged.🤖 Generated with Claude Code