Speed up immediate unpack when freeze: true by 10%#396
Open
skipkayhil wants to merge 2 commits into
Open
Conversation
To use with other, non-symbol, pre-frozen objects.
Since immediates are already frozen, we can skip over "maybe freeze"
behavior completely for those types.
```
ruby 4.0.2 (2026-03-17 revision d3da9fec82) +YJIT +PRISM [x86_64-linux]
Warming up --------------------------------------
control 5.437k i/100ms
frozen before 4.733k i/100ms
Calculating -------------------------------------
control 54.830k (± 1.8%) i/s (18.24 μs/i) - 277.287k in 5.057252s
frozen before 49.078k (± 1.9%) i/s (20.38 μs/i) - 246.116k in 5.014762s
Comparison:
frozen after: 55009.0 i/s
control: 54829.6 i/s - same-ish: difference falls within error
frozen before: 49078.3 i/s - 1.12x slower
```
```ruby
require 'msgpack'
require 'benchmark/ips'
data = []
100.times do
data << rand(0..127)
data << -rand(0..30)
data << nil
data << true
data << false
data << rand(0..65535)
end
packed = MessagePack.pack(data)
up_ctl = MessagePack::Unpacker.new(freeze: false)
up_frz = MessagePack::Unpacker.new(freeze: true)
Benchmark.ips do |x|
x.report("control") { up_ctl.feed(packed); up_ctl.read }
x.report("frozen #{ENV.fetch("STAGE", "after")}") { up_frz.feed(packed); up_frz.read }
x.save!("/tmp/msgpack_un_freeze")
x.compare!
end
```
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.
Rename object_complete_symbol -> frozen
To use with other, non-symbol, pre-frozen objects.
Speed up immediate unpack when freeze: true by 10%
Since immediates are already frozen, we can skip over "maybe freeze"
behavior completely for those types.