Skip to content

Quadratic parse of large top-level { ... } groups (nvm.sh -n takes 52s vs instant) #130

Closed

Description

@caomengxuan666

Found by the open-source corpus scan (nvm-sh/nvm — nvm.sh is one giant top-level brace group; -n takes 51-58s, source ~52s, nvm-exec times out; semantics are correct, purely a perf cliff).

Reproducer: synthetic { + 1200 × x=1 + } parses in 4.2s while the same statements without braces take 0.2s (GNU: instant both ways).

GNU owner: grammar-based group parse, O(n).
Rubash owner: likely re-lex/re-scan per line-group in src/parser/brace_command.rs / src/lexer/brace_scan.rs (skip_brace rescans the accumulated body per joined line).

Artifacts: target/gc/corpus-web/summary.txt finding 3, synthetic reproducer in raw/repro/.

Activity

  1. added
    bug
    on Sep 26, 2026
  2. caomengxuan666 commented on Sep 26, 2026

    @caomengxuan666
    MemberAuthor

    性能专项(target-perf/REPORT.md,release 构建)已确证本项为 O(N².00) 并定位热点:src/lexer/mod.rs:351 每读一条物理行就对整个累积缓冲区重跑 tokenize_plain(mod.rs:340-345 注释自认),叠加 :318/:321/:326 三个 O(L) 全缓冲 has_unclosed_* 扫描;次因 support.rs:308 嵌套重扫。nvm.sh 形态(单 { 组跨 N 行)1000/2000/4000 行 = 896/3588/14263ms(×2 行 → ×4 时间),GNU 9.7ms = 1469×。修复方向 = 增量 tokenize(LexerParseState 重放机制已在);与 #131 的按命令边界增量解析设计同族,可共用车道推进。perf 跟踪单已开(本轮 #155-#159)。

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions