-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Store list of generators with enabled uniqueness for faster clear #1246
Conversation
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.
👍
@@ -34,7 +41,8 @@ def clear | |||
end |
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.
Is there a reason we can't just reassign
def clear
@previous_results = Hash.new { |hash, key| hash[key] = Set.new }
end
That passes all specs and seems to be fast. Is the fear that there would be a big pressure on the GC?
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.
Is this faster than @previous_resuls.clear
?
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'd need to do a proper benchmark, but I noticed this before I started using your new code here which seems plenty fast. Was purely curious what the reasoning was. Thanks so much for this PR btw! Can't wait till it's released because right now i can't use the old implementation
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.
No problem! I'm actually curious about this as well. If you do the benchmarks, please tell us about it.
…ker-ruby#1246) * Store list of generators with enabled uniqueness for faster clear * Update CHANGELOG.md * Update CHANGELOG.md
This PR addresses issue #1186. By keeping a list of generators which used the
unique
feature, it is faster to clear all of them withFaker::UniqueGenerator.clear
, since the latter only needs to go through the objects in the list.