Skip to content

perf(coverage): normalize a path with one fork instead of four - #1105

Merged
Chemaclass merged 1 commit into
mainfrom
perf/1102-normalize-fork
Aug 13, 2026
Merged

Chemaclass merged 1 commit into
mainfrom
perf/1102-normalize-fork

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1102

normalize_path is what the DEBUG trap calls on every cache miss — 494 times
in a single run of one test file, because the caches live in shell variables
and each test body is a subshell. Its body was

echo "$(cd "$(dirname "$file")" && pwd)/$(basename "$file")"

four command substitutions per call.

💡 Changes

  • dirname/basename become parameter expansions, leaving one fork: 2081 ms → 424 ms per 500 calls, and a --coverage run of basic_test.sh 6.4 s → 4.7 s with the same hit count
  • cd+pwd stays deliberately: it resolves symlinks, so /tmp/x normalizes to /private/tmp/x on macOS the way the tracked roots expect. Pure string manipulation is faster still and would quietly stop matching them
  • builtin printf, not printf, so a test spying printf cannot shadow a path the engine depends on — the Spying on printf breaks coverage collection #724 test caught exactly that during development

Note the issue's original premise (path mangling dominates) was wrong and is
corrected in the thread: the memo it proposed bought 4%, this buys 27%.

normalize_path is what the DEBUG trap calls on every cache miss -- 494 times
in a single run of one test file, because the caches live in shell variables
and each test body is a subshell. Its body was

  echo "$(cd "$(dirname "$file")" && pwd)/$(basename "$file")"

which is four command substitutions. Doing the dirname and basename with
parameter expansion leaves one: 2081ms to 424ms per 500 calls, and a
--coverage run of tests/unit/assert/basic_test.sh from 6.4s to 4.7s, with the
same hit count.

The cd and pwd stay. They resolve symlinks, so /tmp/x normalizes to
/private/tmp/x on macOS the way the tracked roots expect; pure string
manipulation would be faster still and would quietly stop matching them.

builtin printf rather than printf, so a test spying printf cannot shadow a
path the engine depends on -- the #724 test caught exactly that.

Closes #1102
@Chemaclass Chemaclass added the enhancement New feature or request label Aug 13, 2026
@Chemaclass Chemaclass self-assigned this Aug 13, 2026
@Chemaclass
Chemaclass merged commit 3fbc3ac into main Aug 13, 2026
38 of 39 checks passed
@Chemaclass
Chemaclass deleted the perf/1102-normalize-fork branch August 13, 2026 08:55
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