Skip to content

perf(bench): recalibrate paste_multiline_bench to the #252 PasteChunkEditMode contract - #261

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/paste-bench-calibration
Oct 12, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/paste-bench-calibration

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Problem

#252 (PasteChunkEditMode) is merged; scripts/perf/paste_multiline_bench.py still measured the pre-#252 world, so its numbers no longer meant anything:

  1. Wrong default workload. Default payload was synthetic/200 lines. The calibrated workload is the issue202 author payload — the 257-line set -euo pipefail build script whose end-to-end wall time defines the repl: PSReadLine-style paste-chunk detection for the Windows console path #252 claim (>300 s timeout → ~4.6 s, CHANGELOG 1.4.0). A naive bench run never reproduced the calibration number.
  2. Timed a dead path. The bracket flavor (default both) implied the repl: enable bracketed paste for GNU bash multiline-paste semantics (#202) #234 bracketed-paste path — but ConPTY swallows the ?2004/?201~ markers (crossterm#737, cited in repl: PSReadLine-style paste-chunk detection for the Windows console path #252), so on Windows a "bracketed" paste through ConPTY exercises the same raw per-line feed as raw. Its timing was a duplicate datapoint under a misleading name. (Unix keeps real Event::Paste and never runs the heuristic — this bench is Windows-only by nature.)
  3. elapsed mixed path cost with harness artifacts. A fixed 0.3 s quiet drain before the submit and up to 1.0 s of Enter-retry quantization sat inside elapsed with nothing separating them from the paste path. On the healthy path the paste is silent (the chunk stays pending until the user's Enter), so the drain was a guaranteed dead-time tax; on a regressed path it could swallow up to 30 s.
  4. No provenance. Output carried no build rev, OS, or repro command — numbers were unattributable.

Fix

  • issue202 is the default payload; the CHANGELOG-calibrated number is what a default run measures.
  • Single raw feed only (the one shape a Windows terminal delivers on Ctrl+V); bracket flavor removed with the reasoning recorded in the module docstring.
  • Harness cadence is now a documented contract (SETTLE_QUIET=0.3 s, ENTER_RESEND=1.0 s) so elapsed keeps its meaning — the CHANGELOG ~4.6 s reference was measured with exactly this cadence. New fields split the number: settle_wait (pure harness wait before the synthetic user's first Enter) and enters_sent (absorbed submit attempts).
  • Bare-line marker matching is incremental (new chunks + carried tail) instead of rescanning the whole accumulator every 0.1 s poll tick, so the harness's own CPU cannot distort timing on a regressed high-output path.
  • Output carries provenance: the niu --version banner (build rev), niubash rev, OS/python/pywinpty versions, payload stats (pasted lines vs the 257-line fixture — the post's trailing blank lines are not paste data) and the exact repro command. --json emits one object per case for CI consumption.
  • Non-Windows runs now explain and exit 2 (cfg(windows) code under test, pywinpty/ConPTY driver) instead of dying on the import; the CI shape is the existing windows-latest + pywinpty setup the perfbudget-trend job already uses (documented in the docstring).

The #202 defect gate is unchanged: bad_executions_paste must be 0 (bare BAD<n> output lines while the paste is still arriving; echoed edit-buffer text does not count) and the marker must execute within --timeout (default 300 s — the ">300 s" calibration bound).

Verified (fresh cargo build of master 11c1612, Windows 10 19045, Python 3.14.7, pywinpty 3.0.5)

paste-bench-env niu="Niubash 1.4.0 — bash-compatible shell for Windows rubash git 41de8319eac1 ..." niubash_rev=11c1612 payload=issue202(253 pasted lines / 257 in fixture, 3981 bytes) os=Windows-10-10.0.19045-SP0 ...
paste-bench-repro python scripts/perf/paste_multiline_bench.py --payload issue202 --lines 200 --timeout 300.0 --exe D:\repo\niubash-wt-pastebench\target\debug\niu.exe
paste-bench payload=issue202 ok=True elapsed=4.58s settle_wait=0.33s enters_sent=5 bad_executions_paste=0 bad_executions_total=0 bytes_out=3749
paste-bench payload=synthetic ok=True elapsed=3.98s settle_wait=0.33s enters_sent=4 bad_executions_paste=0 bad_executions_total=199 bytes_out=3306

Closes the bench-calibration follow-up of #252. No product code touched.

…EditMode contract

The bench still measured the pre-#252 world and its elapsed number mixed
path cost with harness artifacts:

- Default payload was synthetic/200; the calibrated workload is the
  issue202 author payload (257-line fixture, >300 s -> ~4.6 s, CHANGELOG
  1.4.0). issue202 is now the default.
- The bracket flavor timed a path that does not exist on Windows: ConPTY
  swallows the ?2004/?201~ markers (crossterm#737), so a bracketed
  paste through ConPTY exercised the same raw per-line feed as raw — a
  duplicate datapoint under a misleading name (#252 is the Windows
  replacement for bracketed paste; Unix keeps #234's Event::Paste and
  never runs the heuristic). The bench feeds exactly one shape now: the
  raw Ctrl+V burst.
- elapsed smeared in a fixed 0.3 s quiet drain and up to 1 s of retry
  quantization with nothing separating them from the path. The drain is
  now reported as settle_wait (path-vs-harness split), enters_sent counts
  absorbed submit attempts, and the harness cadence (0.3 s settle, 1.0 s
  Enter resend) is a documented contract so elapsed stays comparable with
  the CHANGELOG ~4.6 s reference.
- Bare-line marker matching is incremental (new chunks + carried tail)
  instead of rescanning the whole accumulator every poll tick, so the
  harness's own CPU cannot distort timing on a regressed high-output path.
- Output now carries provenance: the niu --version banner (build rev),
  niubash rev, OS/python/pywinpty, payload stats (pasted lines vs the
  257-line fixture — the post's trailing blank lines are not paste data)
  and the exact repro command. --json emits one object per case for CI.

Windows-only by nature (cfg(windows) code under test, pywinpty/ConPTY
driver): non-Windows runs now explain and exit 2 instead of failing on
the import. CI shape is the existing windows-latest + pywinpty setup the
perfbudget-trend job already uses; documented in the module docstring.

Verified against a fresh build of master (11c1612): issue202 elapsed
4.58-4.60 s (CHANGELOG ~4.6 s), bad_executions_paste 0, bytes_out ~3.7 KB;
synthetic/200 elapsed 3.98 s, bad_executions_total 199 (one execution of
the submitted script, by design).
@caomengxuan666
caomengxuan666 merged commit 3c74e49 into master Oct 12, 2026
8 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/paste-bench-calibration branch October 13, 2026 02:06
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