perf(runner): resolve a test's source location only when needed - #1356
Merged
Merged
Conversation
Every test forked a subshell to read its own definition line:
`$(shopt -s extdebug; declare -F "$fn")`, 1.08ms per call on macOS
arm64 (bash 3.2.57). It produced `<file>:<line>` for a failure message
most tests never emit, and for a report row that add_test discards
before reading when no report is configured. A 500-test file spent
0.35s of 2.75s on it.
Carry the file and function name instead and resolve on the two paths
that render the location. A plain run pays nothing; a run with
`--report-*` pays what it paid before.
The two obvious alternatives are both worse on Bash 3.2, so they are
recorded here rather than retried: a parallel-array map scanned per
test made a 500-test file 7.5ms/test against 6.3ms, because a Bash 3
array is a linked list and indexing is O(i); a single-string map read
with `${map#*$'\n'$fn$'\t'}` made it 19ms/test, because prefix removal
against a leading `*` is quadratic in the string length.
The inputs are not exported. Every consumer runs in a fork, which
inherits them regardless, while an exec'd process gets a function name
its own shell never defined -- which is how a standalone `bashunit -a
assert_same` came to print the location of whichever test had launched
it. It now prints none, and the acceptance snapshot that pinned the
leak loses that line.
perf-fork-budget.md's 0.46ms figure for a bare `$( )` predates arm64
and read as "a subshell is not worth removing"; it now carries the
arm64 numbers.
Closes #1346
Claude-Session: https://claude.ai/code/session_01EXYWTGLjf7qM8Ru3GakDRm
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 #1346
Every test forked a subshell to read its own definition line, building a
<file>:<line>that only a failure message and a report row ever read. On macOS arm64 (bash 3.2.57) that is 1.08ms per test.💡 Changes
--report-*run pays what it did before. A 500-test file went from 2.75s to 2.40s.${var#*pat}is quadratic).bashunit assert …therefore stops reporting the location of whichever test launched it — one acceptance snapshot pinned that leak and loses the line.$( )predates arm64, where the same measurement is 1.1-1.4ms.https://claude.ai/code/session_01EXYWTGLjf7qM8Ru3GakDRm