You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Shrinking of large arrays uses a very large amount of memory #525
I was trying to test a property with the following arbitrary as input:
Arbitraries.randomValue(generateValue).array(long[].class).ofMinSize(1).ofMaxSize(10_000)
// (generateValue is a custom generation function that is not relevant to the problem)
The test works fine on my desktop computer, however, when running tests in a test server with only 1 GB of memory available to Java I got an OutOfMemoryError. Some memory usage profiling seems to indicate that the root cause is the use of Combinatorics.distinctPairs inside ShrinkingCommons.shrinkPairsOfElements. Oddly enough shrinkPairsOfElements is called even though values returned by Arbitraries.randomValue are unshrinkable.
Is there something that can be done to reduce the memory usage during shrinking of large arrays?
Can I somehow explicitly disable shrinking pairs of elements to limit memory usage?
PS: In this particular case adding more memory is not an option. The tests must pass with 1 GB of available memory because the ability to operate with limited memory is also a requirement being tested.
@FeldrinH Many thanks for diving into the problem and the suggestion. Since I'm on holidays I don't have the time to try it out. Maybe you want to go for a PR with the suggested change? I'd personally like a test targeting PairSplitterator to make sure it works as expected.
I implemented your suggestion and together with the fix for stream concatenation suggested in #526 it looks like it is working - and working considerably faster.
@FeldrinH Should I wait for a PR from you or just use it and refer to this issue?
Sorry about the delayed reply. I've been busy.
I have found no issues with the implementation posted here, so the PR would have been just that with a test.
Thanks for accepting this fix. Now I can get rid of the custom patches I've been using.
I just noticed that the release notes have a small mistake. When noting that this issue was fixed, the release notes link to issue 527, but this is issue 525.
Activity
FeldrinH commentedon Oct 26, 2023
I propose that a fairly simple solution would be to generate the pairs dynamically without storing them in a list.
For example something like this:
jlink commentedon Oct 27, 2023
@FeldrinH Many thanks for diving into the problem and the suggestion. Since I'm on holidays I don't have the time to try it out. Maybe you want to go for a PR with the suggested change? I'd personally like a test targeting PairSplitterator to make sure it works as expected.
FeldrinH commentedon Oct 27, 2023
I'll try to look into it. I've already patched jqwik locally and know that the fixes work (or at least don't visibly break the system).
jlink commentedon Nov 15, 2023
I implemented your suggestion and together with the fix for stream concatenation suggested in #526 it looks like it is working - and working considerably faster.
@FeldrinH Should I wait for a PR from you or just use it and refer to this issue?
Fixed out of memory error in shrinking.
jlink commentedon Nov 15, 2023
@FeldrinH Couldn't wait :-) Will give kudos in release notes.
Fixed in c6a2d5b
jlink commentedon Nov 15, 2023
Available in "1.8.2-SNAPSHOT".
jlink commentedon Nov 15, 2023
@FeldrinH Your appreciation is here: https://jqwik.net/release-notes.html#182-snapshot
FeldrinH commentedon Nov 15, 2023
Sorry about the delayed reply. I've been busy.
I have found no issues with the implementation posted here, so the PR would have been just that with a test.
Thanks for accepting this fix. Now I can get rid of the custom patches I've been using.
jlink commentedon Nov 23, 2023
Released in 1.8.2
FeldrinH commentedon Dec 28, 2023
I just noticed that the release notes have a small mistake. When noting that this issue was fixed, the release notes link to issue 527, but this is issue 525.
jlink commentedon Dec 29, 2023
thanks for the catch. Fixed.