Repository navigation
Conversation
Mounting n rows of an each cost n² in two places. A Rust `each`'s region placed its new nodes from the last, each before the one placed last, so every insert moved every row placed so far; new nodes now go in order before the anchor. The renderer looked for the node it inserts before among the parent's children from the front, though rows go before what follows them, near the end; it now looks from both ends. 50,000 rows of a Rust `each` mount in about 260 ms where they took about 510 ms, and 80,000 rows of a TSX `<Each>` show their first frame in about 340 ms where it took 1,345 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Opening a long list or document built with
each/<Each>took time in the square of its rows. Two places did it,one for each kind of
each.Rust
each(core/views.rs).reconcile_regionplaced a region's nodes from the last, each before the one placedlast ("from the last, each before the next, from the anchor"). On a first mount every node is new, so every insert went
in front of all the rows placed so far and moved them along the parent's children (and the layout tree's): n rows moved
n²/2 children.
When every node of the region is new (no parent yet), they now go in order, each right before the anchor. The
reconciliation of kept and moved nodes is unchanged.
TSX
<Each>(nsh-jsdom.rs).insert_beforelooked for the node it inserts before among the parent's childrenfrom the front. Rows go before what follows them, near the end, so n rows looked at n²/2 children.
child_positionnow looks from both ends, as the core'sposition_from_endsdoes. It is used byinsert_before,next_siblingand the removal from a parent.Public API
None.
Performance
cargo test --release -p nsh-core --lib bench_each_mount -- --ignored --nocapture. Setup:FakeEngine, macOS arm64,three alternating runs of the two test binaries against
7d33c400b. Values are ms for the first mount:eachA TSX
<Each>of texts between two texts in a scroll view,nsh test --trace(release, headless, three alternatingruns). Values are ms for the first frame, and for the JS evaluation in it:
nsh test --traceofexamples/counter/App.tsxand ofexamples/bench/RowsTs.tsxscrolled 3,000 pt down and backkeeps their counts (56 ops, 50 mount items; 1,040 ops, 915 mount items). Their times stay within run-to-run spread:
counter 90–197 → 91–143 µs, rows 1,183–1,538 → 1,099–1,428 µs.
The record is in
docs/dev/performance.md. Nothing here touches window showing, frame scheduling or scrolling.Tests
Both new tests fail without the change: 400 rows → 80,200 and 1,600 rows → 1,280,800 children moved; 80,600 and
1,282,400 children looked at.
an_each_mounts_its_rows_in_order_before_what_follows(nsh-core): 400 and 1,600 rows of a Rusteachbefore alast child mount in order. The children moved along grow about four times, not sixteen (
shift_work, test only).rows_inserted_before_a_last_child_look_at_few_children(nsh-js): the same for nodes inserted before a last childthrough
nsh:rt'sinsert(CHILDREN_LOOKED, test only).Other checks:
cargo test --workspace --no-fail-fastpasses exceptnsh-clia_built_record_survives_a_moved_home_and_a_new_timeand
nsh-platform-macosdraw_on_show, which fail onmaintoo.cargo clippy --workspace --all-targetsandcargo clippy -p nsh-platform-web --target wasm32-unknown-unknown --features compiler: no new warnings.🤖 Generated with Claude Code