Skip to content

perf: comsub_residuals Vec<char> materialization in continuation.rs (captain-approved plan A/B from ombperf lane) #292

Closed

Description

@caomengxuan666

From the ombperf lane (captain-reviewed; captain-exclusive file, so this ships as a plan for a lane with the captain applying, or the captain applying directly — not blanket-edited).

Measured (release, OMB load at 828ms after the assoc/array memo fixes 20c2ff3/b62f447c): `has_unclosed_command_substitution` costs 34ms / 984 calls / 2.5MB rescanned (~12x amplification over the 210KB file set). `comsub_residuals` (continuation.rs:1353) opens with `input.chars().collect::<Vec<_>>()()` — every call materializes the accumulated logical line and walks it by index.

GNU anchor: parse.y:3557 read_token is a streaming reader; residual state advances per token and never rescans consumed text.

Plan A (approved, ~2-4x): iterate the &str directly instead of materializing Vec. Caveats beyond the lane sketch that the implementer MUST handle: (1) the state machine has jump-style index assignments (skip_backtick_substitution / skip_parenthesized_unit / skip_arithmetic_substitution return indices; `$'`/`${`/`$(` arms do index += 2) — a plain peekable iterator rewrite does not fit; keep an index model over byte slices or restructure the skip helpers to str; (2) `ch.is_whitespace()` must keep its current Unicode-wide semantics to stay byte-identical (do NOT narrow it to ASCII in the same change); (3) the zero-copy ${...} body views from 15f94b9 slice `chars[index..]` — they need str twins or an as_bytes fast path.

Plan B (approved follow-up, the GNU-shaped fix): resumable ComsubResidualState + `comsub_residuals_from(input, state)` scanning only the appended tail, checkpointed per physical line under the same append-only validity discipline as unclosed_quotes_cache (rubash#241) and brace_scan_cache (depth>=4 lesson: restore position AND state on resume).

Verification bar: byte-identical PS1 md5 / declare -F count / declare -p md5s on the CRLF C: OMB copy; cargo test --lib green; omb-prompt-base tokenize 57.9ms baseline; full OMB load 828ms baseline (expect ~-25ms from A, ~-45ms from B).

Activity

  1. added
    enhancement
    on Sep 28, 2026
  2. caomengxuan666 commented on Sep 28, 2026

    @caomengxuan666
    MemberAuthor

    Delivered by wt10/contperf, captain-applied (75bf9232 + 27759136, master a1f4308+77be9feb): plan B with an honest, well-argued deviation — per-segment incremental scanning was DISPROVEN equivalent (the x="$(fo + o)" counterexample: atomic unit-skips decide on text after the prefix), so the landed mechanism is park/resume: ComsubResidualState (14 fields) + advance() parking at the first of exactly three instability classes (failed $(-unit skip, undecided esac-lookahead past a unit close, backtick-zone heredoc terminator), resumed from a pre-decision snapshot so helpers always see the full current buffer — identical to full-F. Invalidation points enumerated and handled (backslash-join pop, IFS_GLUE insert, comsub-heredoc paren rotation x2, logical-line commit).

    Bonus root cause found on the way: skip_parenthesized_unit mis-lexed <<< as heredoc << + <, swallowing the here-string operand to EOF — 376 of 382 parks on the OMB fixture were this one construct. Fixed per GNU read_token redirection-word assembly; now atomically skipped like other balanced units.

    Numbers: omb-prompt-base tokenize 84.5ms -> 25.0ms; OMB inner load 1010ms -> 867ms (GNU anchor 812-870ms — inside the GNU band); join-gate rescanned bytes 2.61M -> 45K (57x). Equivalence: every-line-prefix terminal-state equality on all 14 fields (4 shapes + park shapes + 4000-case seeded random fuzz), 503/503 lib (+6), 26/26 regression, comsub/comsub2/comsub-eof/comsub-posix/heredoc/redir true-baseline 0 diff, PS1/declare md5 byte-identical.

    Remaining same-family hotspots recorded for follow-up: has_unclosed_quotes and has_unclosed_compound_assignment per-line full scans (same park/invalidity discipline applies, separate semantic proofs needed).

  3. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    Landed by wt12/perf8, captain-applied after review (41dd049, includes reconciling the perf7 answer-cache overlap: unclosed_quotes_cache deleted - the checkpoint model subsumes it; param_open_cache kept - orthogonal function). Mechanism is the #292 plan-B shape: QuotesResidualState (6 fields) + CompoundResidualState (12, with forced_closed terminal carrying) + park classes (quotes Q1 ${-span / Q2 $(-unit+esac-lookahead / Q3 backtick; compound C1-C3) and the same invalidation set as the comsub checkpoint; both legacy functions stay as thin full-scan shells for every other caller.

    Feeder rescans go to ZERO: nvm -n hq 5765 calls/3.62M chars -> 1/172K, hca 5749/4.19M -> 0; nvm load 10.8M/12.5M -> 0/0; head9000 hq 17257 -> 2767 (remainder is the script_driver call site, see below). Wall: nvm -n 635->579ms, nvm load 1221->1123ms. Equivalence: per-line prefix terminal-state equality on all fields + park shapes + 2x3000 seeded fuzz; 7-suite true-baseline byte-identical vs base; nvm-load declare/set dumps byte-identical; 511 lib (+6).

    IMPORTANT re-attribution recorded by the lane: hca was never the configure bottleneck (it never sees the big buffer - gate order). configure's real amplifier is stdin_source_text_needs_more at script_driver.rs:243 calling all four text scanners over the whole stuck group; neutralizing that single call point measured head9000 34s -> 60ms (upper-bound evidence). Next step filed: park-ify unclosed_input_close_char_posix + skip::unclosed_array_subscript_line and switch the script_driver call site to the checkpoint model.

  4. caomengxuan666 commented on Sep 30, 2026

    @caomengxuan666
    MemberAuthor

    perf17 landed by captain review (master 1e7df7f + e3623c6): the comsub park quadratic is gone. Root cause was narrower than the perf11 attribution — ALL 534M re-walked chars (99.6% of the 6018 park resumes on GNU bash own configure -n) were ONE park at the m4sh false-positive backtick stretch's ordinary heredoc, whose park condition closes.is_none() never cleared because closes is the heredoc-HEADER ) signal — None for every ordinary heredoc even after its terminator arrived. The arm now parks only while the terminator line has not arrived (prefix-stable once it has: whole-line terminator search + the join loop appends complete newline-terminated lines — GNU make_cmd.c:512 reads each body line once and never re-reads). configure -n full 3448 -> 1247ms median (-64%), GNU anchor 37-46ms (83x -> 29x). Dispatch-floor round 2 in the same lane: bind_underscore no-op-gated (EXPORTED_VARS rewrite only materialized when the borrowed list actually contains _; typed-store half updated in place) and the empty-alias-table pre-clone removed — p6-null 9.5x -> 8.8x, local3 -12%. Zero-semantic-change: GNU-diff matrices (22 shapes) byte-identical, per-prefix incremental battery, 546/27 green. Remaining configure 29x is the rest of the C/E quote-leak family scanners on the same m4sh stretch (captain continuation territory).

  5. caomengxuan666 commented on Sep 30, 2026

    @caomengxuan666
    MemberAuthor

    perf19 landed by captain review (master 05555e1 + 04bf523): configure -n 1247 -> 420ms (-65%, ~11x GNU 38-39ms). The lane disproved the working hypothesis — the remaining 29x was NOT the quote-leak family and NOT other-scanner parks (those cost ~13ms): ONE group at configure:5176 absorbed the remaining 19578 lines / 525K chars because top-level scanners treat heredoc BODIES as live text (a can'apos-t apostrophe in the <<_ACEOF C-comment body hung single-quote state; the poisoned state then let an m4sh-comment backtick hang to EOF). Three class-level fixes, all GNU-anchored: (1) heredoc bodies opaque to the group scanners (top-level << arm with terminator-not-yet-arrived park, make_cmd.c:512 reads body lines with no quote state; <<< atomic operator parse.y:3690-3706), (2) case-pattern ) closers use a staged case machine with per-push case-depth snapshots (parse.y:1037/3369-3386/3433-3441 — a pattern's ) is a case token; this was a PRE-EXISTING bug the fix exposed, verified failing on pristine base), (3) the history driver now reuses the perf10-certified token stream instead of re-lexing each group. Lane evidence: 42-shape GNU-diff matrices all byte-identical, six upstream suite slices diff counts identical to base, nvm -n/load flat. Residual 420ms = parser 141 + feeder 104 + scanners 26 — the parsearch #281/#292 nested-body re-parse family (architecture-level single-pass reader).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions