perf(runner): stat a marker instead of scanning the shared temp dir - #1270
Merged
Conversation
Every test's EXIT trap expanded
matches=("$BASHUNIT_TEMP_DIR/${BASHUNIT_CURRENT_TEST_ID}"_*)
which makes bash read all of BASHUNIT_TEMP_DIR. That directory is shared
(${TMPDIR:-/tmp}/bashunit/tmp), survives between runs and nothing reaps it, so
every file an interrupted run left there was re-examined by every test of every
later run. It could never match one: the id carries the run's own $$.
Profiling a 200-test run against a real 4242-file directory, this single call
was 3.16ms of an 8.5ms per-test total -- larger than the test body, both hooks,
mock teardown and result encoding combined. A 100-test file:
leftovers 0 500 2000 5000
before 498ms 513ms 635ms 978ms
after 520ms - 520ms 542ms
temp_file/temp_dir now write a <id>_.mark marker (a redirect, not a fork) and
the trap returns early when it is absent -- the common case, since most tests
create no temp file. The marker shares the <id>_ prefix, so the existing rm
takes it along with the rest.
Behaviour change: a file a test writes into BASHUNIT_TEMP_DIR by hand, named
with its own id, is no longer removed for it. Finding one is exactly the
directory scan being removed. The guard test plants such a file and asserts it
survives, which no timing assertion could pin deterministically.
Closes #1269
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 #1269
Every test's EXIT trap expanded a glob over
BASHUNIT_TEMP_DIR, which makes bash read the whole directory. That directory is shared, survives between runs and nothing reaps it — so every file an interrupted run left behind was re-examined by every test of every later run, and could never match, since the test id carries the run's own$$.Profiling a 200-test run against a real 4,242-file directory, this one call was 3.16 ms of an 8.5 ms per-test total — larger than the test body, both hooks, mock teardown and result encoding combined.
💡 Changes
temp_file/temp_dirwrite a<id>_.markmarker (a redirect, not a fork); the trap stats it and returns early when absent, which is the common case since most tests create no temp file. The marker shares the<id>_prefix, so the existingrmtakes it along with the rest