Skip to content
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

Merged
merged 12 commits into from
Jan 8, 2021
Merged

Conversation

marcphilipp
Copy link
Member

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

@codecov
Copy link

codecov bot commented Oct 24, 2020

Codecov Report

Merging #2460 (092751f) into main (74e8de7) will increase coverage by 0.06%.
The diff coverage is 98.56%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...tform/launcher/listeners/LegacyReportingUtils.java 100.00% <ø> (ø) 6.00 <0.00> (ø)
...it/vintage/engine/descriptor/DescriptionUtils.java 88.88% <88.88%> (ø) 3.00 <3.00> (?)
...form/engine/support/hierarchical/NodeTestTask.java 90.09% <94.73%> (+0.29%) 29.00 <3.00> (+2.00)
...r/engine/descriptor/TestFactoryTestDescriptor.java 95.08% <100.00%> (ø) 21.00 <0.00> (ø)
.../engine/descriptor/TestTemplateTestDescriptor.java 100.00% <100.00%> (ø) 19.00 <1.00> (ø)
.../main/java/org/junit/platform/engine/UniqueId.java 81.81% <100.00%> (ø) 23.00 <5.00> (+1.00)
...va/org/junit/platform/launcher/TestIdentifier.java 97.82% <100.00%> (+2.47%) 22.00 <10.00> (+7.00)
...ain/java/org/junit/platform/launcher/TestPlan.java 97.77% <100.00%> (+0.10%) 17.00 <2.00> (ø)
...va/org/junit/vintage/engine/VintageTestEngine.java 100.00% <100.00%> (ø) 8.00 <2.00> (+1.00)
.../vintage/engine/descriptor/TestSourceProvider.java 96.55% <100.00%> (+0.55%) 11.00 <3.00> (+3.00)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74e8de7...092751f. Read the comment docs.

@sormuras
Copy link
Member

About 50% memory savings? Nice!

@mmerdes mmerdes self-requested a review November 30, 2020 08:58
Copy link
Contributor

@mmerdes mmerdes left a 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.

@marcphilipp marcphilipp added this to the 5.7.1 milestone Dec 22, 2020
@marcphilipp marcphilipp force-pushed the issues/1445-reduce-memory-footprint branch 2 times, most recently from c716328 to 90dd6fd Compare December 30, 2020 22:02
@marcphilipp marcphilipp modified the milestones: 5.7.1, 5.8 M1 Dec 31, 2020
@marcphilipp marcphilipp force-pushed the issues/1445-reduce-memory-footprint branch from 90dd6fd to c5efbbd Compare December 31, 2020 12:00
@marcphilipp marcphilipp requested a review from sbrannen December 31, 2020 12:00
@marcphilipp marcphilipp marked this pull request as ready for review December 31, 2020 12:01
@marcphilipp marcphilipp force-pushed the issues/1445-reduce-memory-footprint branch 2 times, most recently from 5ff7537 to 266e8f7 Compare December 31, 2020 12:37
Copy link
Member

@sbrannen sbrannen left a 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.

@marcphilipp marcphilipp requested a review from sbrannen January 7, 2021 15:02
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.
@marcphilipp marcphilipp force-pushed the issues/1445-reduce-memory-footprint branch from fad47fd to 092751f Compare January 8, 2021 19:27
@marcphilipp marcphilipp merged commit 0be0e78 into main Jan 8, 2021
@marcphilipp marcphilipp deleted the issues/1445-reduce-memory-footprint branch January 8, 2021 19:35
@marcphilipp marcphilipp removed this from the 5.8 M1 milestone Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Executing large number of dynamic tests results in OutOfMemoryError: GC overhead limit exceeded
4 participants