Repository navigation
Description
Summary
Benchmarked niu 1.5.0 (rubash engine) vs GNU bash 5.3 on Ubuntu 26.04 with the new hotloop category of unixwin/shellbench — 1771 per-operation cases, each isolating one operation inside an identical for loop wrapper. Median ratio 5.79x slower; 1525/1569 comparable cases behind; only 37 ahead.
Raw data: results/linux-x86_64/20261110-083223-niu-linux-hotloop.json vs 20261109-132813-gnu-linux-hotloop.json in unixwin/shellbench.
Where the time goes (median ns/op ratio, niu/bash)
| area | cases | median ratio | notes |
|---|---|---|---|
test / [ / [[ family |
358 | ~9x | largest single cluster — every loop-condition eval pays it |
| control flow (if/case/nesting) | 82 | 9.8x | |
| readonly / shift / getopts | 15 | 13–18x | worst尖点: readonly pair ops hit 92x, typeset -i 80x |
| eval / declare / typeset | ~60 | 6–9x | |
| mapfile / readarray | 15 | 7.4x | single ops up to 6–7 ms/op |
parameter expansion ${} |
208 | 5.8x | all operator families uniformly slow |
| help / churn / local / fn | ~75 | 5.8–6.6x |
What is NOT the problem
- Loop machinery is fine: bare
:floor case — niu is ~5x faster than bash. - Command substitution is a big win:
$(...)/backquote cases run 5–25x faster than bash (in-process comsub, no fork). Worth keeping. - External spawn (
/bin/true,/bin/echo) is roughly par, slightly slower.
So the gap is concentrated in per-operation dispatch: expansion, test/cond evaluation, variable ops (declare/readonly/shift/unset), builtin invocation overhead — not loop control or process creation.
Repro shape
# ~13x slower end-to-end (user-reported, confirmed):
i=1; time { while [ $i -le 10000 ]; do printf '%d\n' "$i"; ((i++)); done; } > /dev/null
# bash: 0.04s niu: 0.67s
time { i=1; while [ $i -le 10000 ]; do :; ((i++)); done; }
# bash: 0.02s niu: 0.10sSuggested investigation order
test/[/[[eval path (358 cases @ ~9x — biggest cluster)- variable-mutation builtins: readonly/shift/getopts/declare/typeset/unset
${parameter}expansion entry cost- mapfile/readarray (ms-scale per op suggests allocation/copy churn)
Every case is a minimal reproducer — e.g. hotloop.cond_tint_* are test $i -lt 5 in a loop; hotloop.arith_* isolate each arithmetic form.
Generated with Devin
Activity
caomengxuan666 commentedon Nov 10, 2026
归宿:性能专项 / 阶段 3(同 C1–C4 机制评估的归宿口径)。本单只做调查 + 修复排序方案,不派修复波、不改产品代码;调查结果回填本评论。
立案卫生已补:标签
performance+area:builtins+area:expansion+platform:linux+P2-medium+deferred(阶段 3,不在本轮关闭),assignee caomengxuan666,milestone 1.5.1。调查车道已派,工作区
~/workspace/fix-3232/,终报REPORT.md。caomengxuan666 commentedon Nov 10, 2026
调查完成,终报:
~/workspace/fix-3232/REPORT.md(机制图 §3、盒上实测 §5、修复排序 §6)。盒上实测(Simular box,rubash release
beab07dcvs 同机编译 GNU bash 5.3.0,66 操作 × 3 rep 中位;原始日志fix-3232/data/m3232-*.txt):[/[[9.14×(单子 ~9× ✓)、${}展开 9.36×(单子 5.8×)、declare 簇 13.57×、readonly 47.36×(assign 27×、-p/space 67×)、getopts 20×、shift 7–8×、mapfile/read 2.45×(形态与单子不同,待复测)。$(true)命令替换 RB 快 10×(单子 5–25× ✓)。最硬的一条证据(#815 profiler):test 重循环里
[内建本体仅占 2.2%(每调用 0.72µs),解释器自身(funnel + 展开 + 驱动)占 97.8%;展开重循环 99.1% vs 0.9%。test 簇的 ~9× 几乎全是脚手架税,不是 test 本体慢——修 test 本体最多买 2%。对单子一句的订正:“循环机械没问题”不成立。
for ((…))驱动 8.9×、while ((…))条件驱动 27.1×、while :+[…]17.5×;而:与true作循环体几乎无差——:本体便宜,贵的是驱动。单子“裸:快 5×”应是内建本体的孤立计时。修复排序(§6;结构性只给设计与量级估计):P0 每命令脚手架税(字面词快路径 + 内建分发短路 + VarTable 快速哈希;底座 9×→
4–5×,全簇减半)→ P1 readonly / declare10×)→ P2 getopts(20×→-i本体税(67×/42×→10×)→ P310×)→ P4 算术条件驱动(27×→~9×)→ P5[[/cond(15–20×→${}各臂快路径 → P6 mapfile 先复测再定级。归宿仍为性能专项 / 阶段 3,本轮不关闭。另声明:本结论不构成启动全量 VM(#2826–#2828)的论据;与 FNPROTO 函数体编译(1.2–1.7×)正交——分发层税需 funnel/展开重构,不是 VM 能顺带解决的。
Stage-2 ④ Phase 4: variable-attribute family onto Diag (Refs #2707) (#…
caomengxuan666 commentedon Nov 10, 2026
性能债登记(队长,2026-11-11,源 PR #2968 E4 终裁):
PR #2968(declare 族三刀 + E4)以结构证据合入
d9555905,测量案关闭。其性能残差显式记入本单 P1 面(declare 族):caomengxuan666 commentedon Nov 20, 2026
1.5.1 队长分拣(2026-11-20):本条为 P2/P3,不阻塞 1.5.1,拟顺延至发版后处理;点火时以 owner 终裁为准。当前先行处理主干基线波与里程碑内队长修复候选。
fix(redir): materialize undo-save slot saturation EMFILE diagnostics (F…