Skip to content

perf(startup): non-interactive fast path for stdin shells (#562) - #568

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix6/slice-niu-fastpath
Oct 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix6/slice-niu-fastpath

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

perf(startup): non-interactive fast path for stdin shells

Fixes #562

Root cause

stdin 脚本构造器 Shell::new_for_stdin_script() 传 one_shot=false,与 REPL 同等全量构造——其中构造期 load_completion_dirs 扫描并解析补全定义是主要税源(debug 构建 trace:空跑的 completion + widgets 段 618.7 ms、Shell::new 总计 639.8 ms),而两个 stdin 调用点里可证明非交互的情形从未分流到 -c 已有的 one-shot 快路径。

What changed (cluster fix6/niu-fastpath, commit cb44339)

  • 新增 Shell::new_for_stdin_script_fast():命名契约与 new_for_stdin_script 相同(不预绑 __RUBASH_SCRIPT_NAME,由调用方绑 argv[0]);构造走 one-shot 同款 REPL-free 路径(占位 prompt 后端、跳过补全目录扫描、跳过补全状态快照)。
  • 调用点 1:run_stdin_script()(裸 niu、无参数且 stdio 非 tty 才进入,其后永不转交互)。
  • 调用点 2:run_shell_invocation 的 read_stdin 路由,仅当 !invocation.interactive && !stdio_is_interactive() 时用快构造——该条件与两条交互路由的判定恰好互补,快构造的 shell 不可能被提升进任何交互路径。
  • 不动面:-i(含管道 stdin 引擎交互驱动)、tty stdio 的 -s、登录链与 BASH_ENV(均在构造后 source,行为不变,有钉子)、脚本文件路径、-c。
  • 回归测试(名字带 562):shell.rs 单元 2 条 + tests/issue562_noninteractive_fastpath.rs 集成 6 条(空跑 rc、$- 含 s 不含 i、exit 码传播、语法诊断行号、-s+BASH_ENV、-l -s 登录链首存者与 --noprofile、-i 管道仍交互)。

Cargo.lock

不改动。簇报告记录的 signal-hook 0.3.18 锁条目缺 cc 依赖边(一行漂移、--locked 在旧基线 pristine 上即失败)已由当前 master 的 pin 同步提交 2388421 在刷新根锁时一并补上(锁 diff 可见 signal-hook 条目 + "cc" 及数处 windows-sys 边归一到 0.61.2)——故本 PR 不再附 #558 式 hygiene 提交;集成侧 pristine(23884212)--locked 全量实跑正在复核此结论,结果回填本节与验证评论。

Verification (integration, this PR's branch)

  • 集成 pick:cb44339 cherry-pick 到当前 master 2388421 零冲突(新提交 d623f2b,三文件 +364/−9 与原提交一致)。
  • 改动三文件 rustfmt --check 干净、CR 计数全 0。
  • 构建/测试全部经单槽串行(JOBS=1、debuginfo=0、净化环境剥 JARVIS_*);配对 rubash 为同级克隆 e8b65463(与当前 master 锁中 rubash 1.4.3 条目依赖集一致;[patch] 路径覆盖)。
  • 定向:issue562 单元 2 + 集成 6(验证进行中,结果回填评论)。
  • 全量:cargo test --workspace --locked,裁定口径为失败集与 pristine 当前 master(23884212)同机同法实跑逐名相同(验证进行中)。
  • release 口径启动采样不在本 PR 范围:按采样门纪律(load<2 且无 cargo/rustc、双确认)归 gap-v2 窗口补采,簇已备齐 before/after release 二进制与采样脚本;构成分解层面的效果已由 debug trace 证明(修复后空跑 completion 段 618.7 → 0.09 ms,Shell::new 639.8 → 26.3 ms,均为 debug 构建口径)。

A non-interactive stdin run (bare niu over a pipe, niu -s) paid the full
interactive-stack construction - the prompt backend, the completion
directory scan, and the completion snapshot - even though no interactive
session could ever start (measured ~13 ms of the 16.98 ms empty-run p50
against 3.96 ms for -c, whose one-shot constructor already skips it).

Add Shell::new_for_stdin_script_fast: the stdin naming contract of
new_for_stdin_script (no pre-bound script name) with the REPL-free
construction of new_one_shot. Use it at exactly the two points where
non-interactivity is already proven: run_stdin_script (no arguments,
non-terminal stdio) and the read_stdin route of run_shell_invocation
when !invocation.interactive && !stdio_is_interactive() - the exact
complement of the interactive routes below it. -i, terminal stdio, the
login profile chain, and BASH_ENV keep the full constructor and their
existing behavior; script files are unchanged.

Regression pins: runtime unit tests for both stdin constructors
(issue562_*) and tests/issue562_noninteractive_fastpath.rs covering the
empty run, stdin flags/exit codes, diagnostic line numbers, BASH_ENV,
the login chain with --noprofile, and -i over a pipe.
@caomengxuan666

Copy link
Copy Markdown
Member Author

集成验证状态(中间回填):

已完成:cherry-pick cb44339 到当前 master 2388421 零冲突(本分支 tip d623f2b,三文件与原提交一致);改动三文件 rustfmt --check 干净、CR 计数全 0;Cargo.lock 不改动——簇报告记录的 signal-hook 缺 cc 边已由 2388421 的 pin 同步刷新根锁时补上(锁 diff 实查),无需 hygiene 提交。

未完成(基础设施阻塞,非代码问题):pristine 全量、定向 issue562(集成 6 + 单元 2)、slice 全量三步均需经单槽构建队列实跑。今晚本机 6 次整机重启、槽位队列常驻 25–72 个等待者,本集成的排队请求 6 轮均在获得槽位前被重启杀死(累计排队约 7 小时,无部分结果)。簇侧在其基线上的同法验证已全绿(单元 2/2、集成 6/6、全量失败集与 pristine 逐名相同),但集成口径复跑未取得前请勿合并。

续跑已武装:单次持槽的验证链已脱离式重发并排队(pristine 全量 → 定向 → slice 全量,结果落 integration/niu-fastpath/ 的 pristine-test.log 与 slice-test.log),完成或下一人工接手后回填最终结论。release 口径采样不在本 PR 范围,归 gap-v2 窗口补采。

@caomengxuan666

Copy link
Copy Markdown
Member Author

集成验证进展更新:

Phase 1 — pristine 全量 ✅ 已完成(master 2388421,同机同法 cargo test --workspace --locked --no-fail-fast,73 个测试二进制):失败集共 13 条,全部为环境性失败——completion 既有失败 1(runtime_completion_provider,与簇基线同点)、issue153 根斜杠 ×2、issue182 bash-it 互锁 ×1、issue359 启动 pty ×2、issue373 DSR 终端 ×3、repl_command ×1、smoke ×1、smoke_1_3_0 ×2。此跑同时坐实锁结论:--locked 在当前基线全程无解析错误,无需 hygiene 提交。

Phase 2 — slice 进行中:定向集成 issue562 ✅ 6/6 全绿(RC=0);定向单元 2 条与 slice 全量尚欠——第 7 次整机重启打断在单元编译段,phase-2 已单独重发排队(目标目录热)。slice 全量失败集与上述 pristine 13 条逐名比对完成后回填最终结论;在此之前仍请勿合并。

@caomengxuan666

Copy link
Copy Markdown
Member Author

集成验证完成 ✅(同机同法,当前 master 2388421 为基线)

定向:issue562 集成测试 6/6 全绿(RC=0);niubash-runtime lib 单元 2/2 全绿(RC=0:issue562_stdin_fast_shell_skips_repl_only_init、issue562_stdin_full_shell_keeps_repl_capable_init)。

全量:pristine 与 slice 各跑完 73 个测试二进制。pristine 失败集 13 条(全环境性:completion 既有失败 1、issue153 ×2、issue182 ×1、issue359 pty ×2、issue373 DSR ×3、repl_command ×1、smoke ×1、smoke_1_3_0 ×2);slice 失败集 = 同 13 条 + 1 条(见下裁定)。--locked 两跑全程无锁解析错误;改动文件 rustfmt 干净、CR 计数 0。

唯一 delta 的裁定:非回归。多出的是 issue201_epochrealtime::epochrealtime_beats_external_date_for_timing——只测 niu -c 里 $EPOCHREALTIME 展开 vs 外调 date 的耗时比(阈值 50×)。三重证据:①本 PR diff 逐行核查不触碰 -c 分支与引擎(配对 rubash 两跑相同);②slice 上连测 17 次、epoch 段耗时方差 6.6 倍,为调度抢占签名;③同机以 pristine 2388421 构建 niu 做 A/B:手工 epoch 循环 ×5 为 32.9–146.9ms(与 slice 同量级或更差),该测试 6/6 同样失败(比值 x3.0–x26.7)。属本机高负载下的计时 flake,其在 pristine 窗口的一次通过为单次抽中。

结论:失败集除已证非因果的计时 flake 外逐名相同,验证门通过,可合并。release 口径启动采样归 gap-v2,不在本 PR 范围。

@caomengxuan666
caomengxuan666 merged commit f5f347e into master Oct 26, 2026
4 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix6/slice-niu-fastpath branch October 30, 2026 01:42
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.

[perf] Non-interactive empty run pays full interactive-stack init (~13 ms over -c); add a non-interactive fast path

1 participant