go: optimize XDR decoding performance and reduce allocations#225
Draft
tamirms wants to merge 1 commit intostellar:masterfrom
Draft
go: optimize XDR decoding performance and reduce allocations#225tamirms wants to merge 1 commit intostellar:masterfrom
tamirms wants to merge 1 commit intostellar:masterfrom
Conversation
4dafd54 to
3b175b1
Compare
Performance optimizations for Go XDR decoding: - Use byte slice Decoder instead of io.Reader for zero-copy decoding - Preserve slice capacity during decoding (grow-only, no shrinking) - Handle optional types without unnecessary allocations - Union arms with primitive types decode directly into value fields 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3b175b1 to
34f3187
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.
This commit combines several optimizations to significantly reduce allocations and improve decode performance for generated Go code.
depends on stellar/go-xdr#21
API Changes
*xdr.Decoder(byte-slice based)(io.Reader, v)->([]byte, v)Optimizations
1. Byte-Slice Decoder Integration
Replace streaming Decoder with byte-slice based Decoder for direct decoding, providing simpler API and better performance.
2. Enum Validation
Replace map-based validation with faster alternatives:
3. Object Reuse
4. Union Value Types
Store small primitive union arms (≤8 bytes) as values instead of pointers to eliminate allocations during decode:
Larger types (fixed opaque, structs) remain as pointers to prevent memory bloat in unions with many arms.
5. Union Accessor Optimization
Replace ArmForSwitch + string comparison with direct discriminant enum comparison for ~16-23x faster accessor performance.
6. Float/Double and var_array Support
Add explicit encode/decode handling for Float/Double types and variable-length arrays of all primitive types.
Expected Impact
🤖 Generated with Claude Code