-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce memory footprint #2460
Reduce memory footprint #2460
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2460 +/- ##
============================================
+ Coverage 90.46% 90.52% +0.06%
- Complexity 4604 4624 +20
============================================
Files 402 403 +1
Lines 11386 11462 +76
Branches 912 919 +7
============================================
+ Hits 10300 10376 +76
+ Misses 809 808 -1
- Partials 277 278 +1 Continue to review full report at Codecov.
|
About 50% memory savings? Nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Good to have solid test coverage and experimentally measured improvements. Not sure if I oversee all implications. As this touches some core classes another review might be called for.
junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestPlan.java
Show resolved
Hide resolved
c716328
to
90dd6fd
Compare
90dd6fd
to
c5efbbd
Compare
5ff7537
to
266e8f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR looks good.
Thanks for putting in all the effort!
Also, thanks for pushing individual commits that tell a story of the evolution of this PR.
I only spotted a few places for minor improvements, and I left a question or two.
...atform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/NodeTestTask.java
Show resolved
Hide resolved
junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java
Outdated
Show resolved
Hide resolved
junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/descriptor/DescriptionUtils.java
Show resolved
Hide resolved
...tage-engine/src/main/java/org/junit/vintage/engine/discovery/IsPotentialJUnit4TestClass.java
Show resolved
Hide resolved
...gine/src/main/java/org/junit/vintage/engine/discovery/RunnerTestDescriptorPostProcessor.java
Show resolved
Hide resolved
In order to allow them to be garbage collected, dynamic test descriptors are no longer added to their parent’s list of children. This is fine because they were never used in that list.
This reduces the memory overhead of each `TestIdentifier` and each `UniqueId`.
Instead of using a `LinkedHashSet` for empty or single-element sets of tags, we now use the immutable empty set for the most common case of no tags and `Collections.singleton` which is more memory efficient for Single tag sets.
The list of segments of a `UniqueId` is immutable. Prior to this commit, we were using an unsized `ArrayList` to store them which was wasteful since the backing array was often too large.
Instead of storing all `Future` instances we now only store those that Are not yet finished.
`Description.getMethod()` evaluates a regex every time it is called which is expensive for large test suites. `DescriptionUtils` now tries computing it without evaluating a regex first and only falls back on `Description.getMethod()` if the display name does not look as expected.
Test sources are now cached by description which avoids the overhead of creating multiple instances for the same method, e.g. for parameterized tests or generative test suites that include the same class multiple times with different configurations.
This eliminates allocation overhead for the most common case where a `Description` represents a test, i.e. does not have children.
RunnerTestDescriptors can now be garbage collected after they have been executed because they are now removed from the list of children of the engine descriptor.
Prior to this commit each `TestIdentifier` instance required memory for storing a `null` reference.
fad47fd
to
092751f
Compare
With these changes I was able to go from ~57160 to ~125205 dynamic tests with a
-Xmx64m
and the sample project provided by @ben-manes in #2450 without compromising any functionality.I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations