Improve YAMLTree
performance by not using object_id
s
#663
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_id
became 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_identity
in 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_same
in 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?