Closed amomchilov closed 11 months ago
Great find, thank you!
Put this tiny synthetic benchmark together and woah... 7% improvement on net serialization performance!
Comparison:
After removing @targets array: 3030.9 i/s
After switching to identity set: 2975.9 i/s - same-ish: difference falls within error
Before all changes: 2828.5 i/s - 1.07x slower
benchmark.rb
The difference is emphasized here, I chose objects that do minimal other serialization (e.g. simple arrays, no custom class with long names, and cheap field values).
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?