Repository navigation
perf: record each call run of Rust-read rows with one Rust object (native render, level B1) - #266
Merged
Merged
Conversation
This was referenced Oct 23, 2026
Merged
JuroOravec
force-pushed
the
perf/native-render-runs
branch
from
October 23, 2026 09:44
94ee30e to
dc1b647
Compare
…tive render level B1) When Rust read every row of a call run (the rows one c-for places at one component call site), assembly on the precompile path now records the whole run with one Rust object, _NativeRun, instead of one Python record per row, and the manifest writer writes the run's rows from it. Any row or assembly state the run object cannot reproduce exactly sends the run back to the per-row loop, which raises its own errors, so output bytes, errors and callback order stay the same on both paths. - crates/citry_native_render/src/run.rs: RunIds (shared with level A's _RunDigests), first_repeat, write_occurrence_item; fixture test run_items.rs with run_items.json written by scripts/native_render_fixtures.py. - crates/citry_core_py/src/native_render/runs.rs: _NativeRun (try_new, commit, check_invariants, member_ids, occurrences, holds_any) and _NativeOccurrence; _encode_occurrences writes run items given definition_ids. try_new declines on an ordinary exception while reading a row and lets KeyboardInterrupt and SystemExit through. - direct_capture.py: the per-row loop moves into run_members; take_native_run runs first; definition registration splits into native_artifact and register_artifact so a declined run cannot change definition order; the final check calls check_invariants; the view expands each run in place. - protocol.py, events.py, serialization.py, the parity recorder: handle run objects in the view and the manifest; _PreparedResult carries run_definition_ids. - Tests: test_native_render_runs.py (page cases with run counts, the 140-row spy, the assembly comparison, binding refusals), run counts on the level A fault cases, render_both gains runs=(built, declined, held). - Docs: native_render.md section 2 and error modes, AGENTS.md files, a ledger placeholder row for the timing. 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-runs
branch
from
October 23, 2026 10:09
dc1b647 to
8ecdf56
Compare
This was referenced Oct 23, 2026
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
Level A (#265) has Rust read each
simple = "vue"row. Assembly still records every row of ac-forover such a component in a Python loop, one row at a time. That loop computes the row's ids, checks them against what assembly has already seen, writes the row into about a dozen sets and maps, and records one occurrence.With this PR, when Rust read every row of a call run (the rows one
c-forplaces at one component call site), one Rust object,_NativeRun, records the whole run during serialize:take_native_runmakes the checks that depend only on the class: the registry lookup, the component tag, and that the class is the one registered for this engine and not the built-inmarkcomponent._NativeRun.try_newreads every row's record and checks that each row qualifies: the same class, class id, template fragment and call site as the first row, an exactstrkey and render id with a UTF-8 form, and nojs_dataor root markers. It computes both ids of every row and changes nothing in assembly.commitchecks every row against assembly's live state, and only then writes all rows into the maps, in row order.check_invariantsmakes the end-of-assembly checks for the run's rows._NativeOccurrenceper row, in the same place as before. The manifest's occurrence list holds the run object once, and_encode_occurrenceswrites all its rows' items from Rust.If
try_newdeclines orcommitrefuses, the per-row loop records the run exactly as before and raises any error itself. Output bytes, error types and messages, and the order of user callbacks are unchanged on both paths.This level runs only on the precompile path. It does not run for Events updates, for pages with a custom tag callback or a browser hook, or in development mode (which reads no rows in Rust).
Measured
Release wheels of #265 against this branch, Python 3.12, 5 alternating fresh-process pairs of 11 renders of the benchmark board; mean per process.
main-> this PR (A and B1)main-> this PR (A and B1)The bar was at least 3 ms on the collection-free median at 1,400 rows; it measured 4.8 ms (9.0 ms on the mean).
Notable implementation choices
native_definitionis split intonative_artifact(a cache keyed by the fragment) andregister_artifact. Assembly registers a run's definition only aftercommitsucceeds, because the order of first registration is the order the manifest lists definitions in.run_members.take_native_runruns before it._RUN_ROW_CHECK_MESSAGES), so the run path and the per-row path raise the same text._PreparedResultgainsrun_definition_ids, the logical-to-compiled definition ids, set only when the manifest holds a run._manifest_jsonpasses them to the encoder.prepared_manifestchecks each run's definition once for opaque HTML. The Events preparation skips run objects in its opaque HTML andrenderIdloops; an Events instance matching a run row would raiseAssertionError, which cannot happen. Serialize reads a run'stype_keyfor its component tags. The Vue render parity recorder reads definition ids back from the written JSON.AssembledView.occurrencesandPreparedViewMetadata.occurrencesare now typedPreparedOccurrence | _NativeOccurrence, so mypy checks every reader against the attributes a_NativeOccurrencehas.native_render.NativeRunandnative_render.NativeOccurrencehold the Rust classes for thetype(x) ischecks. Where the module is not used, they hold a class that no object belongs to.RunIdsin the pure crate (run.rs) now computes the two ids for both levels;_RunDigestsuses it too.try_newdeclines when reading a row raises an ordinary exception, so the per-row loop meets it at its own row.KeyboardInterruptandSystemExitpropagate.__traverse__, so the cyclic garbage collector does not track them; a test checks this.Accepted differences (none changes output)
Tests
tests/_render_paths.py:render_bothgainsruns=(built, declined, in manifests). A stand-in for the Rust module counts whattry_newbuilds and declines, and a spy onprepared_manifestcounts the run objects the manifests hold. This counts each manifest once even when the Vue render parity recorder writes it a second time.tests/test_native_render_runs.py(56 cases, about 1.5 s on four workers):render_bothwith its run counts. A repeated key in one run makestry_newdecline, and a key repeated across two runs makes the second run'scommitrefuse.try_newdeclines;commitrefusals, each leaving every map unchanged, and a clean commit in row order;check_invariantscases;holds_any;test_native_render_rows.py: the 18 fault cases now also state their run counts (FAULT_RUNS), and the decision table gains a module that has level A's names but not level B1's.crates/citry_native_render/tests/run_items.rschecks ids, repeats and item bytes againstrun_items.json.scripts/native_render_fixtures.pywrites that fixture from Python, and its--checkmode covers it.Gates
scripts/check.py --profile fast --reporter agent):"status": "PASSED", every phase passed.--platform linux.pytest -m "not e2e" -n 4 --python-render-path): 12,793 passed, 145 skipped, 1 xfailed.--cov, run locally on Python 3.14): 89.52%, against a ratchet of 88.5. The coverage settings leave outassemble_typed_render(a line of its signature matches the...exclusion), so B1's assembly code indirect_capture.pyis not counted. Of the counted B1 lines, only the Events-instanceAssertionErroris uncovered, and no page can reach it. A separate focused run without that exclusion shows four uncovered B1 lines in assembly, all defensive: a first row with no call metadata, a registry class from another engine or themarkcomponent, a failedcheck_invariants(it needs a digest collision), and an unfinished definition in the view build.Cross-binding list
crates/citry_native_render/src/run.rsandcrates/citry_core_py/src/native_render/runs.rs.crates/citry_native_render/src/lib.rsexportsRunIds,first_repeat,write_occurrence_itemandOccurrenceItem.rows.rs:_encode_occurrencesgainsdefinition_idsand writes run items, and_RunDigestsnow usesRunIds.mod.rsregisters the two classes._rust.pyihas the two classes and the newdefinition_idsparameter.native_render._REQUIRED_NAMESgains_NativeRunand_NativeOccurrence, so an older module warns and falls back.citry/_vue/native_render.pygains theNativeRunandNativeOccurrenceclass handles.LangImplchange, and no change tocrates/citry_core_py/src/lib.rs.Base
Rebased onto
mainafter #263 and #265 merged; the content is unchanged.🤖 Generated with Claude Code