Repository navigation
Ariadne: the per-frame walk keeps its place on the heap, so any depth draws on a small stack - #1577
Merged
Merged
Conversation
… draws on a small stack The walk (emit, emit_node, emit_container, emit_children and the repeat expansion) recursed once or more per widget level, about 19 KB of stack a level in MSVC Release: 10 levels on a 256 KiB stack, 435 on 8 MiB. It now runs from a work stack on the heap (Runtime::Impl::walk_, stepped by run_walk/step_walk). Each container pushes what it does after its children (its end_*s, pop_ids, scope and function pops, the grid's size write-back, a context menu's end) as a frame, in the order the recursive walk did them, so the backends see the same calls. - emit_node: the window, group, menu, menubar, tabs and custom cases push their leave frame (leave_node) and return; the rest is emit_node_tail, as before. - The repeat expansion (begin_repeat, Op::Instances) and a grid's cells (Op::Cells) are frames, with the outermost repeat's bookkeeping, the per-frame instance cap and the instance's own copy. - The menubar's tail (the loaded documents' menus, the Windows menu, the tray), emit_app_menus, emit_tray and emit_context_menu go on the walk as continuation frames. - run_walk drops what a throwing step left and pops the scopes, functions and repeat it held, as the recursive walk's guards did. - A registered widget fn's ctx.emit runs a walk of its own (the one native nesting left: a level per custom widget whose fn draws a child). - plan_windows_menu (and its first_bar), drop_mount_ticks, the isolation verdict's two tree walks and substitute_index_in go through the tree with an explicit stack too. - Widget copies and frees its tree a node at a time (WidgetNode holds every field but the two subtrees), so a repeat over a deep template, and freeing a deep document, do not recurse. ariadne_deep_nesting_test draws trees thousands of widgets deep (plain groups, every container kind, menus and tray menus, context menus in context menus, repeats over a deep template, a 40-level include: document, a 31-mount load: chain) on a 256 KiB stack, with a counting backend, FtxuiBackend and TvisionBackend. FTXUI lays out nested boxes recursively itself (about 400 bytes a box), so its nested-box test stays at 100. The loader still recurses (about 100 KB of stack a widget level in MSVC Release); its DISABLED_Probe* tests measure where it runs out. CMake/CvcHostStack.cmake and the 40-deep loader test's comment now say loading recurses and drawing doesn't.
transfix
added a commit
that referenced
this pull request
Nov 27, 2026
…a small stack Rebased onto the iterative walk (#1577): - emit_mounts pushes a frame per open mount (its id and emit_path entry, the wrapper on the walk, then a Then that pops them) instead of emitting each in a nested walk. - plan_windows_menu's Mounts case pushes each open mount's tree, then a marker visit that makes it an application if it brought no bar (ARIADNE_SHELL.md 4.9), keeping tree order. - app_menu ends every application's menu through app_commands (Restart, Quit, and Close for a mounts: entry's); one without a bar gets those alone. - drop_mount_ticks seeds its loop with the slots' wrappers. Runtime::set_root's search for the document's own first mounts: slot recursed once a level: it overflowed ariadne_deep_nesting_test's 256 KiB stack on PlainGroups, MenusAndTrayMenus and the FTXUI and tvision plain-group tests. It is a loop now. AriadneDeepNesting.AMountsSlotsEntriesDraw: three entries opened and drawn on the small stack, a window nesting 3000 groups, a bar whose menu nests 3000 submenus, and one without a bar, each with its Close item, every begin_* and push_id balanced.
This was referenced Nov 27, 2026
transfix
added a commit
that referenced
this pull request
Nov 27, 2026
…ell.ari (#1566) * Ariadne shell SH1: mounts:, app-open/app-close, budgets per mount, shell.ari docs/roadmap/ARIADNE_SHELL.md 4.1, 4.2, 4.11 and the SH1 row; ARIADNE.md 6.7. - mounts: <key>: one isolated mount per child of the key (uri, args), loaded through load_mount (expand_load in a fresh context, stateless) with the loader AppRuntime gives the Runtime (Runtime::set_mount_loader). Its init: runs and its on_tick: starts as it opens; it is an application (its bar one menu of the outer bar; one without a bar gets Restart, Quit, Close). Closing quits it, kills every process under its scope and frees its slot; its state stays, so reopening resumes it. Parsed again only when its uri, args or a file changes; hot reload keeps its resident when its program is the same. allow: (a list or { bind }) narrows what may be mounted, a refusal posted to the feed; catalog: names the documents that run as the local principal. The requires: check at mount refuses what the static scan would fail or warn on (a required entry, an unprovided call, gl.scene for a scene: on a host without one). - (app-open URI [AS [ARGS]]) and (app-close AS) on the calling document's first slot; a mounted document gets a PermissionError. - A budget per mount: cvc::state_exec::frame_account (execute_options::account, kept by spawn and fork). The async scheduler charges steps and seconds, ends a run at the limit, and parks a spent account's processes until the next frame (never killed); wake_awaiting starts each account's new frame. Memory is the processes' measured heap shares (process::measures_heap), summed by the Runtime. Defaults by principal (local 100000 steps, 0.025 s, 256 MB a frame; file: and remote: 20000, 0.005 s, 64 MB), settled against every shipped example (busiest: 108 steps, under 0.4 ms a frame). Held for 3 s: a notice whose click offers Allow more, Quit and Restart. The apps mirror carries principal and budget.*; processes.ari shows each share. - data: uri: { arg: NAME }; a menu_item: label that is an expression. - components/shell.ari (--catalog in gallery.json format, --open), an Apps menu, a Launcher, processes.ari, a mounts: slot; examples/ariadne/documents/shell_apps.json (tray_demo, json_feed, apps/counter). - The .ari schema learns mounts:, allow:, catalog: and uri: { arg }. Tests: AriadneMounts.* (open, close with its memory freed, reopen with state kept, the verbs, a refused URI, unmet requires:, hot reload, a busy mount held while another runs, a mount past its memory, the shipped examples within the local budget), AriadneComponents.ShellOpensIts- CatalogOnDemand, AriadneLoader.MountsSlotAndADataUriFromAnArgument and LoadMountParsesAn- EntrysDocument, AsyncSchedulerTest.AFrameAccountHoldsItsProcessesToTheirFrame, and ari_run_shell_{ftxui,tvision} (tmux, Linux). * mounts: compare an allow: or catalog: path in the resolver's canonical form On the Windows CI runner the temp directory is spelled with an 8.3 short name (C:\Users\RUNNER~1\...). The slot's base comes from the resolver, which uses weakly_canonical, so it holds the long name. The entry's path was only made lexically normal, so the two never matched, and AriadneMounts.ARefusedUriIsPostedToTheFeed saw its allowed file refused. mount_norm now makes a local path canonical the way the resolver does (links followed, short names spelled out), and keeps a trailing slash so an allow: prefix still matches only under its directory. Reproduced and verified locally by running ariadne_runtime_test with TMP set to a short path: all 377 pass. * mounts: no recursion on a deep document, and a mounts: slot drawn on a small stack Rebased onto the iterative walk (#1577): - emit_mounts pushes a frame per open mount (its id and emit_path entry, the wrapper on the walk, then a Then that pops them) instead of emitting each in a nested walk. - plan_windows_menu's Mounts case pushes each open mount's tree, then a marker visit that makes it an application if it brought no bar (ARIADNE_SHELL.md 4.9), keeping tree order. - app_menu ends every application's menu through app_commands (Restart, Quit, and Close for a mounts: entry's); one without a bar gets those alone. - drop_mount_ticks seeds its loop with the slots' wrappers. Runtime::set_root's search for the document's own first mounts: slot recursed once a level: it overflowed ariadne_deep_nesting_test's 256 KiB stack on PlainGroups, MenusAndTrayMenus and the FTXUI and tvision plain-group tests. It is a loop now. AriadneDeepNesting.AMountsSlotsEntriesDraw: three entries opened and drawn on the small stack, a window nesting 3000 groups, a bar whose menu nests 3000 submenus, and one without a bar, each with its Close item, every begin_* and push_id balanced. * mounts: a mounts: entry's state: block is written as it opens #1563 added a document's state: block. A load:ed module's seeds are written at its sub-prefix just before its init:, once, and again on a Restart. A mounts: entry's wrapper carries the same seeds (load_mount goes through expand_load), but open_mount ran only its init:. That marked the mount done in ran_inits, so the seeds were never written. open_mount now writes them just before the init:, under the same once-only check. Reopening resumes without writing them, and a Restart writes them again (emit_container, as for a load: module). AriadneMounts.AMountsStateBlockIsWrittenAsItOpens checks that init: reads the seeds, a reopen keeps a changed value, and a Restart writes the seeds again. It fails without the fix: the mount opens but count is empty. ARIADNE.md 5.3 and 6.7 and the ARIADNE_SHELL.md 4.2 note say so. * mounts: no function-local static for a slot without a spec mount_principal and open_mount each kept a `static const MountsSpec kNoSpec` to stand for a slot without a spec. A function-local static of a non-trivial type is a bss object and a guard variable, so the writable-data scan on package-linux / libcvc-release-grpc failed on four symbols that are not on the allowlist. Each is now a local MountsSpec: an empty one costs no allocation, and nothing is left process-wide.
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.
Ariadne's per-frame walk no longer recurses: a document nested any depth draws in the same native stack. Asked for by Joe while SH1 (#1566) hit the stack edge ("validate the walk as stackless, as the DSL is, and make it iterative now").
Don't merge without Joe's OK.
What changes
Runtime::Impl::walk_, stepped byrun_walk/step_walkinsrc/cvc/ariadne/ariadne.cpp).emit,emit_node,emit_container,emit_childrenand the repeat expansion recursed once or more per widget level. Now each container pushes what it does after its children as a frame, in the order the recursive walk did it:emit_node's window, group, menu, menubar, tabs and custom cases push a leave frame (leave_node) and return; what every widget does last isemit_node_tail, unchanged.begin_repeat,Op::Instances) and a grid's cells (Op::Cells) are frames, with the outermost repeat's bookkeeping (emitting_repeat_, mount ticks), the per-frame instance cap and the instance's own copy.emit_container's end (end_grid, the tracks/columns write-back, the scope and function pops) isOp::Container; a context menu's end isOp::ContextMenu.emit_app_menus,emit_trayand its overflow menu go on the walk as continuation (Then) frames.run_walkdrops what a throwing step left and pops the scopes, functions and repeat it held, as the recursive walk's guards did.render()and recursed are loops over an explicit stack:plan_windows_menu(and itsfirst_bar),drop_mount_ticks, the isolation verdict's program and hole walks,substitute_index_in.Widgetcopies and frees its tree a node at a time (inc/cvc/ariadne/widget.h): a newWidgetNodebase holds every field but the two subtrees (children,context_items), andWidget's copy constructor and destructor go through a work list. Without it, a repeat over a deep template (copied each frame) and freeing a deep document still recursed. No field changed name or meaning;context_menu/context_menu_idmoved intoWidgetNode.ctx.emitdraws its child where the fn asks, between its own calls, so it runs a walk of its own: a native level per custom widget whose fn draws a custom widget. (The only registered fn in the tree, cvcGL'slabeled, draws two texts.)CMake/CvcHostStack.cmakeand the 40-deep loader test now say loading recurses, drawing doesn't.Depth before and after
Windows 11, MSVC 14.44 Release, each number the deepest that passed, bisected, on a
boost::threadwith that stack (ariadne_deep_nesting_testwithCVC_ARI_DEEP_STACK_KIB/CVC_ARI_DEEP_DEPTH; master is 327a791 with the same test file).The walk (a counting backend; plain groups, then every container kind, then menus and tray menus):
About 19 KB of stack per widget level before (
emit_node's frame alone is 14.6 KB in Release, 23.5 KB in an MSVC Debug compile). After, a step of the walk takes a fixed amount of stack: every test passes on 64 KiB butFtxuiDrawsNestedContainers(below), and 100000 widget levels draw there.A 40-level
include:document (loaded on the 8 MiB main thread) drew on 256 KiB only up to 9 levels on master; it draws on 64 KiB now.The loader is unchanged and still recurses (yaml-cpp's parser does, and so does
parse_widget):About 100 KB of stack per widget level:
parse_widget_impl's frame is 95,168 bytes (__chkstk 0x173C0), a slot for every Widget temporary in its branches, and it is on the recursive path once a level. So the 41/42 edgeari snapshothit on master was the loader, not the walk. Shrinking that frame and a loader nesting limit with a clear error, sized for the smallest shipped stack, are the follow-up planned in transfix/workstreams#4259; the probes (DISABLED_ProbeLoad*) are there to re-measure it.Shipped stacks: the wasm builds link
-sSTACK_SIZE=2097152(ari's browser build, arigl, arigl-web, cyprty, the examples) or 8 MiB (ariglx), not Emscripten's 64 KB default; Windows hosts and tests 8 MiB (CvcHostStack.cmake); Linux 8 MiB.Tests
src/cvc/tests/ariadne_deep_nesting_test.cpp(new), modelled onstate_exec_deep_data_test'son_small_stack(256 KiB,CVC_ARI_DEEP_STACK_KIBoverrides): every body draws on the small stack, two frames, and checks the deepest thing was drawn and everybegin_*/push_idwas closed.WidgetCopiesAndFreesADeepTreeOnASmallStack(20000 levels and a context menu)PlainGroups(10000),EveryContainerKind(3000: a group with an id, pointer handler, right-click menu and disabled scope; a grid cell; a tab bar; a mount with functions; a window; a horizontal row),MenusAndTrayMenus(5000-deep submenus in the bar, in a tray icon in the overflow menu and in a shown one),ContextMenusInContextMenus(2000),RepeatsOverADeepTemplate(5000, nested repeats as grid cells)FtxuiDrawsPlainGroups,FtxuiDrawsMenusAndContextMenus,FtxuiDrawsNestedContainers(100 nested grids, item groups and context areas); tvision:TvisionDrawsPlainGroupsADocumentNestedThroughIncludesDraws(40 levels, as the loader test; counting backend and FTXUI),ADocumentNestedThroughLoadsDraws(31 nestedload:mounts, the loader's cap, each with its owninit:)DISABLED_ProbeLoadIncludes,DISABLED_ProbeLoadInlineGroups,DISABLED_ProbeDrawIncludesmeasure the loader and the old walk.Two limits these found that are not the walk's:
FtxuiDrawsNestedContainersstays at 100 (ten times what the old walk drew on 256 KiB) for Debug lanes' headroom. A fix would go in cvcpkg's FTXUI recipe or flatten boxes inftxui_backend.cpp; not here.instance_key) and an unnamed item's id spell out its place in the tree, so each costs more the deeper it is; the context-menu tests use 2000 levels for that. The existing key scheme, not the stack.Verified (Windows, MSVC Release, this box's .deps build with FTXUI and tvision)
ariadne_runtime_test368,ariadne_loader_test272,ariadne_host_test66,ariadne_ftxui_test126: all pass, unchanged.ariadne_deep_nesting_test: 12/12 at 256 KiB; at 64 KiB 11/12 (FtxuiDrawsNestedContainersexceeds FTXUI's own recursion there, above)..aridocuments underexamples/and 7 built ones (grids with repeats and hidden cells, row splits and tables, menus with the Windows menu merged, collapsed menubars, tray icons with menus and the overflow menu, context menus on windows, groups and the root, tabs, item groups, disabled scopes, mounts and repeated mounts with menubars as applications, nested repeats, backdrops, autofocus), three frames each, with menus open, closed, and a backend with no tray: 168 traces, byte-identical between master and this branch.ari snapshot(FTXUI) of every example document: identical output on master and this branch (the 9 the terminal host draws; the rest are refused forgl.sceneby both).ctest -R ^ari_: the ari command tests built here pass.cvcgl_ariadne_frame) wasn't run here.emit_nodeat 23.5 KB,step_walk5.2 KB,render8 KB, so a step stays well inside 256 KiB on the Debug lanes too (GCC's Debug-with-coverage frames weren't measured).Not verified here: cvcGL's ImGui goldens (not built on this box; CI runs them), Linux and macOS (CI), wasm (no emscripten build here; its frames weren't measured).
Conflicts
#1566 (SH1) edits the same walk: it adds
case Kind::Mountscallingemit_mounts(which loops over its mounts and callsemit()per mount), changescase Kind::MenuItemAction, and adds aKind::Mountscase toplan_windows_menu's walk. Whichever merges second rebases: on this branchemit_mountsshould push its wrappers as frames (aThenper mount, or aChildren-like frame), sinceemit()from inside a step runs a nested walk;plan_windows_menu'sKind::Mountscase goes in the loop's switch as before.