Repository navigation
with ast: one buffer per list and a fill printed as written; check_.w >36 min -> 0.15 s (#1358) - #1513
Merged
Conversation
Contributor
Author
|
Stack #1516 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main + #1509 → … → #1515 (head 63e8340): build ok, :fixpoint ok (stage2 == stage3 with DWARF variables), :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merge the stack: |
ehartford
marked this pull request as ready for review
September 23, 2026 16:30
… written; check_.w from >36 min to 0.15 s (#1358) Two causes, found by timing `ast` per top-level declaration of lib/std/tommyds/check_.w: 37 declarations dump in 0.01 s each and one, `var the_cache: [16777216]u8 = [0 as u8; 16777216]`, takes the time. 1. The parser desugars `[v; N]` into N copies of v's one node, and the renderer printed every copy: 16,777,216 elements, about 150 MB of dump for a 50-byte declaration. 2. The renderer grew each list with `out = out ++ piece` after `if i > 0: out = out ++ ", "`. The append after the `if` lowers to the copying with_str_concat_n (lower_if forgets the string flow facts, so `out` may alias and the in-place move_first append is refused; filed as #1491), so each element copied the whole list so far: a fill of 16000 dumped in 0.38 s, of 64000 in 6.32 s. `sample` of the check_.w run: 1851 of 2161 samples in str_concat_n_copy, 246 in move_first. render.w: every string accumulator is a StringBuilder (a one-off Lexer-free rewrite of the `var out = ..`/`out = out ++ ..` lines, completed by hand where the type checker flagged a use), and an NK_ARRAY_LIT whose elements are all one node (only the fill desugar produces that) prints as `[v; N]`. Evidence, `ast` of every tracked .w file (3392) with stage1 before and after this change: 3325 dumps byte-identical; the other 63 are byte-identical once each `[E; N]` of the new dump is expanded back into N copies of E; the 4 that timed out at 20 s before now finish. Times before -> after: check_.w >20 s (>36 min in the issue) -> 0.15 s, lib/std/re/defs.w >20 s -> 0.12 s, rt/fiber_core_{darwin,windows}.w >20 s -> 0.01 s, lib/std/build.w 12.7 s -> 0.02 s, src/compiler/LlvmBridge.w 9.3 s -> 0.02 s. A written literal of 40000 / 160000 elements: 2.00 s / 29.34 s before, 0.10 s / 0.43 s after. test/behavior/behav_ast_dump_linear.w: the check_.w fill dumps as `[0 as u8; 16777216]` (before: killed at its 120 s capture timeout), and a written list's dump time at 4N stays within the test/complexity bound of the time at N. The fill desugar itself (N extras per fill, and `[v; N]` with a const N silently building one element) is #1478.
ehartford
force-pushed
the
fix-1358-ast-linear
branch
from
September 23, 2026 19:37
4a749bf to
8a03ad3
Compare
This was referenced Sep 23, 2026
Merged
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.
Closes #1358.
Root cause. Timing
astper top-level declaration oflib/std/tommyds/check_.w: 37 declarations dump in 0.01 s each; one,var the_cache: [16777216]u8 = [0 as u8; 16777216], takes the time.[v; N]into N copies of v's one node, and the renderer printed every copy: 16,777,216 elements, ~150 MB of dump for a 50-byte declaration.out = out ++ pieceafterif i > 0: out = out ++ ", ". The append after theiflowers to the copyingwith_str_concat_n(lower_ifforgets the string flow facts, so the in-placemove_firstappend is refused — filed as MIR: a string self-append after an if statement copies the whole string (lower_if forgets string flow facts): s = s ++ f() in a loop is quadratic #1491), so each element copied the list so far: a fill of 16000 dumped in 0.38 s, of 64000 in 6.32 s.sample: 1851/2161 samples instr_concat_n_copy.Fix. Every string accumulator in
render.wis aStringBuilder, and anNK_ARRAY_LITwhose elements are all one node (only the fill desugar produces that) prints as[v; N].Evidence.
astof every tracked .w file (3392) with stage1 before/after: 3325 dumps byte-identical; the other 63 are byte-identical once each[E; N]of the new dump is expanded back into N copies; the 4 that timed out at 20 s now finish. Before → after: check_.w >20 s (>36 min in the issue) → 0.15 s, lib/std/re/defs.w >20 s → 0.12 s, rt/fiber_core_{darwin,windows}.w >20 s → 0.01 s, lib/std/build.w 12.7 s → 0.02 s, src/compiler/LlvmBridge.w 9.3 s → 0.02 s. A written literal of 40000 / 160000 elements: 2.00 s / 29.34 s before, 0.10 s / 0.43 s after.Test.
test/behavior/behav_ast_dump_linear.w: the check_.w fill dumps as[0 as u8; 16777216](before: killed at its 120 s capture timeout), and a written list's dump time at 4N stays within the test/complexity bound of the time at N.Found on the way: #1478 (
[v; N]with a const N silently builds one element; the desugar stores N extras).