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

Store list of generators with enabled uniqueness for faster clear #1246

Merged
merged 4 commits into from
Jul 19, 2018
Merged

Store list of generators with enabled uniqueness for faster clear #1246

merged 4 commits into from
Jul 19, 2018

Conversation

MarcPer
Copy link
Contributor

@MarcPer MarcPer commented May 24, 2018

This PR addresses issue #1186. By keeping a list of generators which used the unique feature, it is faster to clear all of them with Faker::UniqueGenerator.clear, since the latter only needs to go through the objects in the list.

@vbrazo vbrazo self-requested a review July 19, 2018 01:46
Copy link
Member

@vbrazo vbrazo left a comment

Choose a reason for hiding this comment

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

👍

@vbrazo vbrazo merged commit 166417a into faker-ruby:master Jul 19, 2018
@MarcPer MarcPer deleted the speed_up_unique_clear branch July 19, 2018 08:15
@@ -34,7 +41,8 @@ def clear
end
Copy link

@maschwenk maschwenk Feb 5, 2019

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?

Copy link
Contributor Author

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?

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

Copy link
Contributor Author

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.

davidmorton0 pushed a commit to davidmorton0/faker that referenced this pull request Jul 12, 2021
…ker-ruby#1246)

* Store list of generators with enabled uniqueness for faster clear

* Update CHANGELOG.md

* Update CHANGELOG.md
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.

3 participants