perf(console): read the clock and pad a line through return slots - #1358
Merged
Conversation
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
This was referenced Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Background
Related #1348
Four spots still captured a value through
$( )where the house return-slot variant already existed next door.rpadis 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 aperlfork.💡 Changes
bashunit::str::rpad_to_slotand use it on the per-test line;rpadbecomes the thin echo wrapper, the shapestrip_ansialready has. Saves 0.74ms per test wherever per-test timing is on.printf— the only fork-free printf into a variable isprintf -v, which is Bash 3.1.clock::inittonow_to_slot. A file defining both hooks costs 5.6ms less on Bash 3.2; this repo has 115 of them.strip_ansi_to_slotchanges strategy.https://claude.ai/code/session_01EXYWTGLjf7qM8Ru3GakDRm