Repository navigation
Ariadne: a repeat's instance is one copy of its template, not one per level - #1365
Merged
Merged
Conversation
… 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.
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.
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% inWidget's copy constructor alone. The rest of the walk (predicates, pictures, players, ImGui) was about 20%.substitute_indexcopied 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'scard_listinstance is a few hundred nodes, aWidgetis 1088 bytes in wasm32, and with JS exceptions each member copy is aninvoke_*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:
substitute_index(inclusive)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 therepeattests, doesn't link on this Windows box: gtest'sFLAGS_gtest_death_test_styleis 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 theinvoke_*overhead on what remains.