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

Remove calls to Object#object_id #241

Merged
merged 6 commits into from
Nov 10, 2024
Merged

Conversation

amomchilov
Copy link
Contributor

@amomchilov amomchilov commented Nov 2, 2024

Ruby 3 added GC compaction, which generally improves performance, but complicates Object#object_id (it's no longer as simple as twiddling with the object's address, since that's no longer stable). Since Ruby 2.7 object_id became more expensive, particularly on its first call for a particular object. There's giant WeakMap under the hood which tracks the association between objects and their IDs. Here's a great blog post about it.

This PR removes usages of object_id, and replaces them with faster alternatives. See the individual commits for details.

Testing with a 5 MB sample PDF, CombinePDF.load(file).save("file.pdf) gets about 1% faster

@amomchilov amomchilov marked this pull request as ready for review November 2, 2024 22:04
Copy link
Owner

@boazsegev boazsegev left a comment

Choose a reason for hiding this comment

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

Thanks! 😀🙏🏻

I love the use of compare_by_identity and equal? which I didn't properly dig into before.

@boazsegev boazsegev merged commit 8108fb6 into boazsegev:master Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants