Problem
record_line caches two decisions per file — whether it is tracked, and its
normalized path — in shell variables. The test body runs in a subshell, so
those variables are a copy that dies with it, and the next test rebuilds them
for every file it touches.
Instrumenting one run of tests/unit/assert/basic_test.sh against
--coverage-paths src: 5718 record_line calls, 1427 of them cache misses
over only 13 distinct files. Thirteen files, eleven hundred redundant
misses.
A miss is the expensive path (Bash 3.2 arm64, per 500 calls):
| |
|---|
should_track | 1130 ms |
normalize_path | 1843 ms (424 ms after #1102) |
lookup_put x2 | 62 ms |
Proposal
Warm the caches in the parent, before the first test subshell, from the
tracked list seed_tracked_files already builds (#1053). A subshell inherits
the parent's variables, so every worker starts with the decisions already
made and the miss path runs about thirteen times per run instead of 1427.
The spelling matters: the trap keys on whatever BASH_SOURCE holds, which is
how the file was sourced — often ./src/x.sh rather than the absolute path
the seed list carries. Warming both spellings covers the common cases, and a
miss still falls through to the current path, so nothing breaks when a file
arrives spelled some third way.
Related
#1102 makes each miss ~4x cheaper; this removes most of them entirely. The two
compose.
Problem
record_linecaches two decisions per file — whether it is tracked, and itsnormalized path — in shell variables. The test body runs in a subshell, so
those variables are a copy that dies with it, and the next test rebuilds them
for every file it touches.
Instrumenting one run of
tests/unit/assert/basic_test.shagainst--coverage-paths src: 5718record_linecalls, 1427 of them cache missesover only 13 distinct files. Thirteen files, eleven hundred redundant
misses.
A miss is the expensive path (Bash 3.2 arm64, per 500 calls):
should_tracknormalize_pathlookup_putx2Proposal
Warm the caches in the parent, before the first test subshell, from the
tracked list
seed_tracked_filesalready builds (#1053). A subshell inheritsthe parent's variables, so every worker starts with the decisions already
made and the miss path runs about thirteen times per run instead of 1427.
The spelling matters: the trap keys on whatever
BASH_SOURCEholds, which ishow the file was sourced — often
./src/x.shrather than the absolute paththe seed list carries. Warming both spellings covers the common cases, and a
miss still falls through to the current path, so nothing breaks when a file
arrives spelled some third way.
Related
#1102 makes each miss ~4x cheaper; this removes most of them entirely. The two
compose.