Skip to content

[perf] 执行器热路径残余(#156/#157/#158/#186 关闭后):read 循环 106x / fn 调用 94x / s+=x 77x / 展开 76x / 算术 50x / 内建循环 52x / 启动 13x #242

Closed

Description

@caomengxuan666

来源

perf-suite 车道首个可复现基准(scripts/run-perf-suite.sh + benchmarks/,基线 docs/PERF-BASELINE.md,rubash 9bf2df9 debug vs WSL GNU bash 5.3.0,2026-09-27)。#156/#157/#158/#186 均已关闭,但热路径在同量级探针上仍普遍 >= 10x:

探针 形态 rubash GNU 比值
benchmarks/13-readloop-gen-x2000.sh 生成 2000 行 | while read 2549ms 24ms 106x
benchmarks/07-fncall-noop-x5000.sh 空函数调用 ×5000 3480ms 37ms 94x
benchmarks/06-strconcat-x5000.sh s+=x ×5000 1915ms 25ms 77x
benchmarks/15-expansion-x5000.sh ${a#..}/${a%%..} 混合 ×5000 4492ms 59ms 76x
benchmarks/04-loop-true-builtin-x2000.sh 内建 true 循环 ×2000 1048ms 20ms 52x
benchmarks/05-arith-x5000.sh (( i += 1 )) ×5000 648ms 13ms 50x
benchmarks/11-pipeline-yes-head.sh yes | head -100000 221ms 8ms 28x
benchmarks/10-pathmiss-x100.sh command -v 未命中 ×100 261ms 24ms 11x
benchmarks/01-startup-empty.sh / 02 启动底价 92/89ms 7ms 13x

对照组(接近持平,说明成本不在进程创建):`` ×1000 = 1.2x(477ms vs 382ms);外部命令 spawn ×300 = 1.5x(316ms vs 215ms)。echo\|while read(12)= 5.7x 而 13 = 106x:管道本身只 ~6x,read 内建/简单命令分派是放大器(与 #186 每命令前导码论断一致)。

注:每行含 msys timeout 包装的常量开销(rubash 侧 ~10-20ms,启动行略被高估,详见 PERF-BASELINE.md 的 caveat)。

复现

cargo build && bash scripts/run-perf-suite.sh   # 全套 ~8 分钟

Activity

  1. added
    enhancement
    on Sep 27, 2026
  2. added 2 commits that reference this issue on Sep 27, 2026
  3. caomengxuan666 commented on Sep 28, 2026

    @caomengxuan666
    MemberAuthor

    perf3 round (wt7/perf3 @ c17b6cea) hot-path progress — re-scoped with numbers, stays OPEN:

    probe 92de75b base perf3
    04-loop-true-builtin-x2000 1048ms / 52.4x 626ms / 41.7x
    05-arith-x5000 648ms / 49.8x 456ms / 38.0x
    15-expansion-x5000 3407ms / 56.8x 3293ms / 54.9x (back-to-back A/B medians 3545→3418 under host load; walker-guard 769→508ms, allocs 3.58M→3.04M)
    08-cmdsub-true-x1000 1.2x 1.0x (spawn parity retained)
    09-external-uname-x300 1.5x 0.8x (parity retained)

    Landed: walker ${-arm inline fragment resolution (no pipeline re-entry for =-free fragments; SubXpassFrame memo shares the enclosing word's frame), case_pattern_matches literal-equality admission (no Vec staging per candidate boundary in prefix/suffix removal), allocation-free remove_matching boundary walk, expand_parameter_pattern_word literal admission. Verification: 120-case ${...} GNU-diff matrix byte-identical (target/issue-suites/results/perf3/), lib 482/482, regression 24/24. Remaining probe-15 cost is the per-command loop machinery (test/[ invocation, $((...)), word expansion of $a refs) — distributed, no single >5% structural win left in this layer without semantic rework (confirms perffix's finding).

  4. added a commit that references this issue on Sep 28, 2026
  5. caomengxuan666 commented on Sep 28, 2026

    @caomengxuan666
    MemberAuthor

    perf4 round (wt8/perf4) hot-path progress — re-scoped with numbers, stays OPEN:

    probe lane base (9a13e8f, morning) back-to-back A/B vs pristine base (same load)
    04-loop-true-builtin-x2000 591ms / 45.5x 612 -> 584ms (-4.6%)
    05-arith-x5000 450ms / 37.5x 472 -> 475ms (flat)
    15-expansion-x5000 3191ms / 54.1x 3299 -> 3237ms (-1.9%)
    08-cmdsub-true-x1000 1.2x 1.4x — spawn parity RETAINED
    09-external-uname-x300 1.5x 0.9x — parity RETAINED

    The -25% target is NOT met this round. Landed: the per-command preamble's env stamps (__RUBASH_CURRENT_LINE / __RUBASH_CMD_START_LINE) paid key+value String allocations on every executed command (30k commands on probe 15); they now render into a stack buffer and assign only when the line moved (public_accessors.rs). The exec-profile decomposition after the change confirms the remainder is the same distributed cost perffix/perf3 already characterized: assignment-RHS expansion work (execute_empty_words_command), [ /test word expansion, $((...)) evaluation, and the bash_command_source_text render — no single >5% structural win without semantic rework of expansion/assignment internals. Next candidates if a lane takes this up: the per-command command-text renderer (needs a mutation-safe memo), and the $a-reference expansion path inside the walker.

  6. added 3 commits that reference this issue on Sep 28, 2026
  7. added
    P2-medium
    on Oct 9, 2026
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

    P2-mediumenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions