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 Hamster::Set in checksummer for speed #887

Merged
merged 1 commit into from Jul 1, 2016

Conversation

denisdefreyne
Copy link
Member

Using Ruby’s Set in an immutable way is slow. Hamster::Set, from Hamster, is significantly faster.

Example: 1138s → 50s

Fixes #864.

digest.update(obj.class.to_s)

if visited.include?(obj)
digest.update('<recur>')
else
digest.update('<')
behavior_for(obj).update(obj, digest) { |o| update(o, digest, visited + [obj]) }
behavior_for(obj).update(obj, digest) { |o| update(o, digest, visited.add(obj)) }
Copy link
Member Author

Choose a reason for hiding this comment

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

I could’ve left it that way, but #add is a nicer API, and it’s likely faster as well.

@denisdefreyne denisdefreyne merged commit b2d0fb8 into release-4.2.x Jul 1, 2016
@denisdefreyne denisdefreyne deleted the hamster-set-in-checksummer branch July 1, 2016 20:17
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

1 participant