Repository navigation
perf(startup): non-interactive fast path for stdin shells (#562) - #568
Conversation
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.
|
集成验证状态(中间回填): 已完成:cherry-pick 未完成(基础设施阻塞,非代码问题):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 窗口补采。 |
|
集成验证进展更新: Phase 1 — pristine 全量 ✅ 已完成(master 2388421,同机同法 Phase 2 — slice 进行中:定向集成 issue562 ✅ 6/6 全绿(RC=0);定向单元 2 条与 slice 全量尚欠——第 7 次整机重启打断在单元编译段,phase-2 已单独重发排队(目标目录热)。slice 全量失败集与上述 pristine 13 条逐名比对完成后回填最终结论;在此之前仍请勿合并。 |
|
集成验证完成 ✅(同机同法,当前 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 条(见下裁定)。 唯一 delta 的裁定:非回归。多出的是 结论:失败集除已证非因果的计时 flake 外逐名相同,验证门通过,可合并。release 口径启动采样归 gap-v2,不在本 PR 范围。 |
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 后端、跳过补全目录扫描、跳过补全状态快照)。run_stdin_script()(裸niu、无参数且 stdio 非 tty 才进入,其后永不转交互)。run_shell_invocation的 read_stdin 路由,仅当!invocation.interactive && !stdio_is_interactive()时用快构造——该条件与两条交互路由的判定恰好互补,快构造的 shell 不可能被提升进任何交互路径。-i(含管道 stdin 引擎交互驱动)、tty stdio 的-s、登录链与 BASH_ENV(均在构造后 source,行为不变,有钉子)、脚本文件路径、-c。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)
cargo test --workspace --locked,裁定口径为失败集与 pristine 当前 master(23884212)同机同法实跑逐名相同(验证进行中)。Shell::new639.8 → 26.3 ms,均为 debug 构建口径)。