Shopify / protoboeuf

Experimenting with a protobuf implementation
MIT License
24 stars 2 forks source link

Avoid allocation with the offset option for `String#unpack1` #93

Closed XrXr closed 2 months ago

XrXr commented 2 months ago

Instead of using byteslice and then using unpack1, we can pass the offset to unpack1 and skip allocating a string. This option was added in Ruby 3.1, which seems fine since CI only tests as old as 3.2.


I regenerated stuff under lib/protoboeuf/protobuf/ so it picks up the new changes. Other files might be stale too since there are more changes than what I touched.

Gives a decent boost:

Before:

Comparison:
     decode upstream:      109.2 i/s
   decode protoboeuf:       41.7 i/s - 2.62x  slower

Comparison:
decode and read upstream:        6.6 i/s
decode and read protoboeuf:       35.9 i/s - 5.47x  faster

After:

Comparison:
     decode upstream:      107.5 i/s
   decode protoboeuf:       44.9 i/s - 2.39x  slower

Comparison:
decode and read upstream:        6.5 i/s
decode and read protoboeuf:       37.8 i/s - 5.79x  faster
maximecb commented 2 months ago

Thanks Alan. Very cool :D

We might need to regenerate the benchmark in yjit-bench as well.