[PROTOTYPE] Add optimized_struct option for fast Struct serialization#387
Draft
gmalette wants to merge 2 commits intomsgpack:masterfrom
Draft
[PROTOTYPE] Add optimized_struct option for fast Struct serialization#387gmalette wants to merge 2 commits intomsgpack:masterfrom
gmalette wants to merge 2 commits intomsgpack:masterfrom
Conversation
Adds a C-level fast path for serializing and deserializing Ruby Struct types, bypassing Ruby proc callbacks entirely. Usage: factory.register_type(0x01, MyStruct, optimized_struct: true) Benefits: - Directly accesses struct fields via RSTRUCT_GET in C - No Ruby method calls for field access - No proc allocation or invocation overhead - Supports both regular and keyword_init structs The wire format is identical to the recursive proc-based approach, ensuring compatibility with existing serialized data. This provides significant performance improvements for applications that serialize many Struct objects.
byroot
reviewed
Dec 11, 2025
|
|
||
| puts "\nBenchmarking scenario: P:#{scenario[:products]} V:#{scenario[:variants]} PM:#{scenario[:product_metafields]} VM:#{scenario[:variant_metafields]} SPG:#{scenario[:spg]} SP:#{scenario[:sp]}" | ||
|
|
||
| payloads = coders.map { |coder| coder.factory.dump(data) } |
Member
There was a problem hiding this comment.
Suggested change
| payloads = coders.map { |coder| coder.factory.dump(data) } | |
| payloads = coders.map { |coder| coder.factory.dump(data).freeze } |
FYI: If the payload is frozen, it saves a bunch of work for msgpack. The diff isn't massive, but on you simple benchmark it gives another ~0.10x over marshal.
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.
This is a prototype, please don't actually merge this as I cannot write C code and this is all Claude-generated.
The idea is to add a C-level fast path for serializing and deserializing Ruby Struct types, bypassing Ruby proc callbacks entirely.
The wire format is identical to the recursive proc-based approach.