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

Share already loaded fixtures across test classes #51001

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

casperisfine
Copy link
Contributor

@casperisfine casperisfine commented Feb 7, 2024

self.class is a fairly narrow cache key, so it doesn't hit that much, but more importantly, since nothing clears that cache, on large test suites it keeps growing extremely large.

Using the list of fixtures as a cache key doesn't strictly solve the growth issue, but most classes actually load all fixtures so this should shrink the cache size considerably.

Instead we can use the parameters of load_fixtures as a cache key, and clear the entire cache when changes, this both improve the hit rate and solves a memory leak.

cc @ChrisBr

`self.class` is a fairly narrow cache key, so it doesn't hit that much,
but more importantly, since nothing clears that cache, on large test
suites it keeps growing extremely large.

Using the list of fixtures as a cache key doesn't strictly solve
the growth issue, but most classes actually load all fixtures so
this should shrink the cache size considerably.
@ChrisBr
Copy link
Contributor

ChrisBr commented Feb 7, 2024

Thanks for the quick fix, confirming this is solving the memory leak for us ❤️

This was roughly the memory consumption for us before the patch, after it completely vanished from the profile:

100 tests - 38.76 MB
200 tests - 75.91 MB
400 tests - 152.53 MB

@byroot byroot merged commit bab4aa7 into rails:main Feb 7, 2024
4 checks passed
@casperisfine casperisfine deleted the fixtures-cache-key branch February 7, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants