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

Use weak references in register_* functions so that garbage collection still works #3135

Merged
merged 1 commit into from Nov 22, 2021

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Nov 3, 2021

See #3131; this is a nice performance optimization for anyone registering lots of transient Random instances.

I experimented with using the same technique under register_type_strategy() etc., but there are so many can't-be-weak caches, closures, and references involved in strategy internals that there's no practical way to make it happen without serious performance degradation.

The exception to that is unwrap_cache, where if the outer strategy is dropped we certainly don't need to remember what it wrapped; it's a small but cheap memory-use reduction.

@Zac-HD Zac-HD added the performance go faster! use less memory! label Nov 3, 2021
@Zac-HD Zac-HD marked this pull request as ready for review November 4, 2021 10:05
@rsokl rsokl self-requested a review November 5, 2021 14:08
Copy link
Contributor

@rsokl rsokl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks good, and it a nice improvement for heavy RNG users. The use of count is elegant!

@Zac-HD Zac-HD merged commit 798e967 into HypothesisWorks:master Nov 22, 2021
@Zac-HD Zac-HD deleted the weakref-registries branch November 22, 2021 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance go faster! use less memory!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants