Skip to content

Ariadne: a repeat's instance is one copy of its template, not one per level - #1365

Merged
transfix merged 1 commit into
masterfrom
perf/ariadne-repeat-one-copy
Nov 19, 2026
Merged

transfix merged 1 commit into
masterfrom
perf/ariadne-repeat-one-copy

Conversation

@transfix

Copy link
Copy Markdown
Owner

nicotina's feed scrolls and glides at about half the display's rate in the browser: every frame took ~34 ms of main-thread work on an idle feed (headless Chrome as a phone, 390×844 at 3×, an 8-post stub feed).

A CPU profile of the wasm build, with function names, put 75.7% of the main thread in substitute_index, and 54% in Widget's copy constructor alone. The rest of the walk (predicates, pictures, players, ImGui) was about 20%.

substitute_index copied a widget along with its whole subtree, then cleared the children and copied each child again the same way, one level down. So a node was copied once for every level above it in the instance: every frame, for every instance of a repeat. A feed's card_list instance is a few hundred nodes, a Widget is 1088 bytes in wasm32, and with JS exceptions each member copy is an invoke_* through JS.

Now the template is copied once and the index is substituted through the copy in place (substitute_index_in). A field without {i} is left alone, where before it was copied out and back. What gets substituted, and where, is unchanged: nested repeat templates are still left untouched, and a mount's scope still gets .i.

Measured on the same page, before and after, with the same objects otherwise:

before after
main-thread work per idle frame 33.6 ms (p90 38.7) 12.9 ms (p90 14.6)
frames during a fling's glide 35.1 ms mean, 82 of 87 over 33 ms 17.9 ms mean, none over 33 ms
substitute_index (inclusive) 75.7% 22.6%

Tests, run locally, all pass:

  • cvcgl_ariadne_repeat: 40 checks.
  • ariadne_loader_test: 242.
  • ariadne_media_test: 60.
  • cvcgl_imgui_group_click.

ariadne_runtime_test, which has most of the repeat tests, doesn't link on this Windows box: gtest's FLAGS_gtest_death_test_style is unresolved, which is unrelated to this change. CI runs it.

What's left: one deep copy per instance per frame (22.6%) and the predicates (15%). Both still grow with the number of posts loaded. Skipping instances scrolled out of view, or keeping instances between frames, would remove most of that, but each changes the runtime's behaviour or memory, so they aren't in this PR. -fwasm-exceptions (JX2) removes the invoke_* overhead on what remains.

… level

substitute_index copied a widget with its whole subtree, then threw the children away and
copied each one again, the same way, one level down: a node was copied once for every level
above it in the instance, every frame, for every instance. A feed's card_list (a few hundred
nodes a card) spent three quarters of the browser frame there (75.7% of the main thread in a
CPU profile of nicotina's feed in wasm, Widget's copy constructor 54%). Now the template is
copied once and the index substituted through the copy in place, and a field without {i} is
left as it is rather than copied out and back.
@transfix
transfix merged commit a7acb63 into master Nov 19, 2026
29 checks passed
@transfix
transfix deleted the perf/ariadne-repeat-one-copy branch November 19, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant