Repository navigation
Improve YAMLTree performance by not using object_ids - #663
Merged
Merged
Conversation
Object IDs became more expensive in Ruby 2.7. Using `Hash#compare_by_identity` let's us get the same effect, without needing to force all these objects to have object_ids assigned to them.
object_ids and improve Registrar performanceobject_ids and improve YAMLTree performance
object_ids and improve YAMLTree performanceYAMLTree performance by not using object_ids
Member
|
Great find, thank you! |
YAMLTree performance by not using object_idsYAMLTree performance by not using object_ids
amomchilov
commented
Dec 18, 2023
| @obj_to_node = {} | ||
| @obj_to_id = {}.compare_by_identity | ||
| @obj_to_node = {}.compare_by_identity | ||
| @targets = [] |
Contributor
Author
There was a problem hiding this comment.
@tenderlove Looking again... is @targets just completely unused? Only ever shoved into, never read.
Merged
Contributor
Author
|
Put this tiny synthetic benchmark together and woah... 7% improvement on net serialization performance!
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since Ruby 2.7,
object_idbecame more expensive, particularly on its first call for a particular object. @jemmaissroff has a great blog post about it.We can reduce how many objects we assign object IDs to, by using
Hash#compare_by_identityin theYAMLTree::Registrar. The semantics will be the same, but now loads/stores into the Hash are faster, and we don't need to trigger lots of object ID assignments.On a related note, I used
assert_samein the tests, where applicable (instead ofassert_equal a.object_id, b.object_id).Is there a benchmark suite I can run to compare before/after performance?