Marshal load perf#9365
Merged
headius merged 4 commits intojruby:masterfrom Apr 14, 2026
Merged
Conversation
Fixnums, true, false, and nil cannot be partially unmarshaled and are never registered with the partial map, but the previous code still attempted to remove them from that map. Likely due to overhead from acquiring and installing an identity hash code in RubyFixnum objects, this appears to have significantly degraded Marshal.load performance for large numbers of int-ranged Integer objects as reported in jruby#9136. The change here removes the "leave" logic from the marshal load logic for core types which cannot be partial and which do not get registered with the partial map via an "entry" call. This improves performance of the reported benchmark back to JRuby 1.7.27 levels.
The partials map is only used to avoid invoking the caller's proc with a partially-initialized object, such as one that is still loading instance variables. If no proc was given, partially- initialized objects will never be visible, so there's no reason to track them. This commit eliminates the use of the partials map completely in that case. This alone would be sufficient to fix jruby#9136, but previous commits also removed the partials usage for core types that do not get registered in it. The change here dramatically improves the performance of loading nearly all types of values in bench/bench_marshal_load.rb and also reduces allocation by eliminating the partials map when unused.
Many uses of Marshal will not encounter the same objects in the stream, so don't allocate these link-tracking collections until needed.
9ba8960 to
e5f5c51
Compare
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.
Several performance improvements for Marshal.load based on the benchmark and results in #9136: