Skip to content

perf(parser): fast-bail the function-definition probe for plain commands - #1647

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/parse-fast-bail
Oct 25, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/parse-fast-bail

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

perf(parser): fast-bail the function-definition probe for plain commands

单文件改动 src/parser/function_command.rs(+22 行),基线 master d15a02df(cherry-pick 自 perf-parse 簇交付 commit 3849319,基线 e8b65463,零冲突)。

剖面结论摘要

  • shellbench parse 类五条均为 shell -n {script} 口径;插桩剖面(线程 CPU 时钟计数器,争用免疫)显示:脚本路径的成本由 feed / parse / exec 三段每行、每命令固定地板大致均分,parse 段内函数定义机器占 funcs1500 parse 的 64%。
  • 其中失败探针是纯浪费:parse_function_command_with_diagnostic 在每个命令起始处被探测,普通简单命令占绝大多数,却要先走 lt/bang 名字重组走查 + 候选名 Token 两次 String 克隆,才轮到括号检查并返回 None——剖面定版约 0.73µs/命令起始恒定付出(simple3000 语料 parse 段 2.2ms/3000 条)。
  • 本改动在探针入口加 O(1) 准入:非 function 关键字形时,后续 token 是 ()/(、起始 token 是 RedirectIn <、或 Keyword ! 三者皆无则直接返回 None,跳过重组与克隆;function 关键字形保持全路径。

等价性 desk 审计结论(簇侧已完成)

准入放行集恰好等于原代码可返回 Some 的形状全集,逐 return 点核对:

  • near_error 各分支都在 keyword_form 内(function 关键字形不走准入);
  • special_group 必须以 < 或 ! 起始;
  • 普通名字形需名字后紧跟 ()/(,且名字有效性检查之后还有一道括号检查兜底。

被拒形状在原路径上必然落到 None,零行为变化。

验证状态(如实分列)

已过:

  • cherry-pick 到当前 master 零冲突,单文件 +22 行;
  • 改动文件 per-file rustfmt clean(簇侧);改动文件 CR 计数 0。

待跑(构建门 load<7 且 MemAvailable>1.5G,集成线正在门控执行,结果回填本 PR):

  • lib 全量 --skip login_posix_env(期望与 master 基线同集:771 过 / 1 失败 ownership_unary_operators_check_existing_file / 1 ignored);
  • parser 诊断族回归 7 文件;
  • 246 差分(稳定失败集应 = {gl08, ms10});
  • 改动文件 fmt/CR 在集成树复核。

性能数字口径声明

  • 本 PR 不给正式性能结论。正式 shellbench 采样有 load<2.0 硬门,与 gap-v2 同批在安静窗口补测,回填 PERF-BASELINE 资产。
  • 本 PR 附带的是 CPU 口径(rusage 子进程 CPU)before/after 指示值:基线二进制(master d15a02df)vs 集成树二进制,parse 类五条 shell -n,争用环境下采集——只作方向性指示,不得把争用环境数字写成结论。
  • 预期量级(剖面推算):约 0.6–0.7µs/命令起始,即 parse 段约 10%、总路径约 4% 的边际改善;非数量级变化。残余靶子(exec 主循环簿记、函数定义本体、feeder 尾门群等)见簇报告 §6,另行成簇。

parse_function_command_with_diagnostic is probed at every command
start, and almost every probe is an ordinary simple command that
walks the lt/bang name reassemblies and clones the candidate name
token only to return None. Admit only the shapes that can answer
Some -- a name token directly followed by () or (, a <(...)' name
(RedirectIn <), or a !! name (Keyword !) -- and bail before the
walk otherwise. The `function` keyword form keeps the full path.
Zero behavior change: every entry the admission rejects provably
fell through to None before.

Measured (thread-CPU profile): the probe cost ~0.75us per command
start on simple corpora (2.2ms of parse per 3000 commands).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Integration verification on current master 6bedad97 + this commit (branch rebased from d15a02df, new tip 0f63a3e, remote sha verified via gh api). All cargo steps ran inside the build slot (JOBS=1, RUSTFLAGS="-C debuginfo=0", purified env with JARVIS_* stripped); the differential and the CPU battery only execute the built binaries.

Gate Result
build --locked (baseline master + integrated tree) ✓ both clean
lib full (--skip login_posix_env) 771 passed / 1 failed / 1 ignored; sole failure = ownership_unary_operators_check_existing_file (pre-existing root-env baseline item — identical set to pristine master)
parser-diagnostic regression files (issue1290/1524/1537/1538/1553/1554/1560) 7/7 rc=0 (70 passed / 0 failed / 1 ignored in aggregate)
306-case differential (--target rubash, fresh results) 303 pass / 3 fail: known-stable {gl08, ms10} — this tree does not contain the #1609 fix, so that is the expected set — plus ps06, adjudicated a timing flake by isolated re-runs (3 PASS / 2 FAIL of 5; its script races two near-instant jobs under wait -n, same shape as its recorded flake history). Effective failure set = {gl08, ms10}
rustfmt / CR on the changed file clean / 0

CPU battery (rusage children CPU, shell -n, median of 5, debug binaries: pristine master 6bedad97 vs integrated 0f63a3e; two samples taken):

case sample 1 ratio sample 2 ratio
simple3000 0.938 1.033
funcs1500 1.080 1.022
control2000 1.015 0.794
expand2000 0.990 0.971
mixed5000 1.001 1.010

Caliber statement (unchanged from the PR body): these are contention-environment indication values (machine load ~6.5–14 with parallel builds running), not formal benchmark results. Per-case ratios swing widely between samples and center on ~1.0 — this setup's noise floor is above the marginal effect the cluster estimated (~4% of total path), so the battery resolves no directional signal: no claimable speedup and no re-run-surviving regression signal either. The hard evidence stays the desk equivalence audit (admission set == exactly the shapes the original probe could return Some for, checked return-point by return-point) plus the profile counters. Formal ratios still wait for the gap-v2 strict sampling window (load<2.0, no cargo running), to be published with the baseline update.

Full record: SLICE-PERF-PARSE-REPORT.md §3/§4 in the integration workspace (incl. the process note: the verification chain was killed twice by runtime restarts while queued for the build slot and was re-armed idempotently; final run completed in a single slot acquisition).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant