fix: register setUp only once, eliminating O(N²) accumulation. ~2x faster tests that can scale in 1 file#175
Open
jpohhhh wants to merge 2 commits intoBetterment:mainfrom
Open
fix: register setUp only once, eliminating O(N²) accumulation. ~2x faster tests that can scale in 1 file#175jpohhhh wants to merge 2 commits intoBetterment:mainfrom
jpohhhh wants to merge 2 commits intoBetterment:mainfrom
Conversation
Each call to goldenTest() was calling goldenTestAdapter.setUp(_setUpGoldenTests), appending a new setUp callback to the current test group every time. With N golden tests, all N callbacks ran before each of the 2N variant runs, producing 2N² total setUp executions (e.g. 20,000 for 100 tests). The fix guards the registration with a boolean so it happens exactly once. Benchmarked against a real project (442 golden tests, 63 files, --concurrency=1): | Metric | Before (0.13.0) | After (fix) | Improvement | |----------------|-----------------|-------------|-------------| | Peak RAM | 18.1 GB | 3.2 GB | 5.6× | | Wall time | 212 s (3:33) | 127 s (2:07)| 1.7× | | Test execution | 3:08 | 2:02 | 1.5× | | User CPU | 180.8 s | 85.8 s | 2.1× | | System CPU | 46.1 s | 17.7 s | 2.6× | | Page reclaims | 12.7M | 4.9M | 2.6× | The system CPU drop (46s → 18s) reflects kernel time spent on memory management (page faults, VM pressure) servicing the pathological allocation pattern. The O(N²) rapid-fire async setUp calls were starving the GC of idle time, preventing it from finalizing native rendering resources (Pictures, Images, surfaces) between test runs. A regression test is included that intercepts setUpFn/testWidgetsFn to prove the accumulation and its quadratic effect.
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.
Story
Description
Each call to goldenTest() was calling goldenTestAdapter.setUp(_setUpGoldenTests), appending a new setUp callback to the current test group every time. With N golden tests, all N callbacks ran before each of the 2N variant runs, producing 2N² total setUp executions (e.g. 20,000 for 100 tests).
The fix guards the registration with a boolean so it happens exactly once.
Benchmarked against a real project (442 golden tests, 63 files, --concurrency=1):
The system CPU drop (46s → 18s) reflects kernel time spent on memory management (page faults, VM pressure) servicing the pathological allocation pattern.
A regression test is included that intercepts setUpFn/testWidgetsFn to prove the accumulation and its quadratic effect.
Type of Change