Skip to content

perf(console): read the clock and pad a line through return slots - #1358

Merged
Chemaclass merged 1 commit into
mainfrom
feat/1348-return-slots-rpad-clock
Sep 9, 2026
Merged

perf(console): read the clock and pad a line through return slots#1358
Chemaclass merged 1 commit into
mainfrom
feat/1348-return-slots-rpad-clock

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1348

Four spots still captured a value through $( ) where the house return-slot variant already existed next door. rpad is fork-free inside, so the subshell around it was its whole cost; the file hooks read the clock four times per file, which on Bash 3.2 wraps a perl fork.

💡 Changes

  • Add bashunit::str::rpad_to_slot and use it on the per-test line; rpad becomes the thin echo wrapper, the shape strip_ansi already has. Saves 0.74ms per test wherever per-test timing is on.
  • Padding is a slice of a doubled run of spaces, not a printf — the only fork-free printf into a variable is printf -v, which is Bash 3.1.
  • Switch the four file-hook clock reads and clock::init to now_to_slot. A file defining both hooks costs 5.6ms less on Bash 3.2; this repo has 115 of them.
  • The slot variant is tested against the capture on plain, empty, ANSI-coloured, truncating and over-1024-character input — the last because that is where strip_ansi_to_slot changes strategy.

https://claude.ai/code/session_01EXYWTGLjf7qM8Ru3GakDRm

Four spots still captured a value through `$( )` where the return-slot
variant was already sitting next door.

`rpad` is fork-free inside, so the subshell around it was its entire
cost: 0.74ms per test wherever per-test timing is on, which is Bash 5 by
default and any shell with --show-execution-time. It gets a
`rpad_to_slot`, and `rpad` becomes the thin echo wrapper, the same shape
`strip_ansi` has over `strip_ansi_to_slot`.

Padding is a slice of a doubled run of spaces rather than a `printf`,
because the only fork-free printf into a variable is `printf -v`, which
is Bash 3.1 and this project floors at 3.0.

The file hooks read the clock four times per file through `$( )`, which
on Bash 3.2 wraps a `perl` fork: 5.6ms per file with both hooks, over
115 such files here. `run_test` was converted to `now_to_slot` already;
these and `clock::init` were missed.

The slot variant must produce exactly what the capture produced, with
the trailing newline `$( )` stripped, so the tests compare the two on
plain, empty, ANSI-coloured, truncating and over-1024-character input --
the last because that is where strip_ansi_to_slot changes strategy.

Closes #1348

Claude-Session: https://claude.ai/code/session_01EXYWTGLjf7qM8Ru3GakDRm
@Chemaclass Chemaclass added the enhancement New feature or request label Sep 9, 2026
@Chemaclass Chemaclass self-assigned this Sep 9, 2026
@Chemaclass
Chemaclass merged commit 6eced76 into main Sep 9, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the feat/1348-return-slots-rpad-clock branch September 9, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant