Repository navigation
perf(snapshot): build direct rendered text in one loop, not three arrays per element - #48
Merged
Merged
Conversation
The extractor allocated three arrays per element (childNodes copy, filter, map) to build one string, for 11,668 elements on the 21.9k-element fixture. One index loop produces the same text; heavy snapshot 116.6 -> 102.6 ms in 40 interleaved real-path rounds, mid/small within noise. Adds a source gate and a behavioural case; 544 answers byte-identical to the base. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Contributor
|
Measurement context for this change (CAPY-28):
|
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.
directRenderedTextinagent/src/snapshot.jsallocated three arrays per element (Array.from(childNodes), afilter, amap, anotherfilter) to build one string. On the 21,916-element fixture it runs for 11,668 elements and was the second-largest leaf of the snapshot walk. It is now a single index loop overchildNodes.Why
Measured while attributing the action path (CAPY-28). The walk is the constraint: a trivial
browser_evaluateon the heavy fixture is 95 ms, of which 92.7 ms is one page-side snapshot evaluation; the Rust side of the action is 1.4–2.4 ms.Proof
2be3331: 408 across four shaping budgets (default, 65536×200, 32768×120, 16384×80) over tiny/small/heavy/forms; 40 live-ref answers over five pages; 96 find/snapshot answers over six pages including an 8k-element mid fixture. The find needles matter because a rendered name is only observable throughbrowser_find.mcp/tests/fixtures/snapshot_w2_test.js: fails if the extractor stops being a braced loop, ifArray.fromreturns, or if.filter(/.map(returns to its body; plus a behavioural case pinning the join ("Alpha beta Gamma"from five text nodes, two blank).Array.from(childNodes)→ gate red while the behavioural case stays green (the work gate, not the text gate, is what catches it); change the join separator → behavioural case red.--test-threads=1).2be3331: identical output for core, CLI, MCP and agent after path normalisation.