-
Notifications
You must be signed in to change notification settings - Fork 205
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
Improve YAMLTree
performance by not using object_id
s
#663
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_id
s and improve Registrar
performanceobject_id
s and improve YAMLTree
performance
object_id
s and improve YAMLTree
performanceYAMLTree
performance by not using object_id
s
Great find, thank you! |
YAMLTree
performance by not using object_id
sYAMLTree
performance by not using object_id
s
@obj_to_id = {} | ||
@obj_to_node = {} | ||
@obj_to_id = {}.compare_by_identity | ||
@obj_to_node = {}.compare_by_identity | ||
@targets = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tenderlove Looking again... is @targets
just completely unused? Only ever shoved into, never read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in #665
Put this tiny synthetic benchmark together and woah... 7% improvement on net serialization performance!
|
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?