-
Notifications
You must be signed in to change notification settings - Fork 624
Apply ValueRlpStream optimizations to RlpStream and ValueDecoderContext #9208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
status? |
8704cdb to
9e4ccde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ports the ValueRlpStream performance optimizations to RlpStream and Rlp.ValueDecoderContext, and centralizes shared logic in a new RlpHelpers class to reduce duplication and improve hot-path efficiency.
- Introduces RlpHelpers with branchless prefix length calculation and shared length deserialization/throw helpers
- Replaces if/else chains with switch expressions and extracts cold paths with NoInlining
- Simplifies SkipItem/SkipLength using PeekNextRlpLength/PeekPrefixLength
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Nethermind/Nethermind.Serialization.Rlp/ValueRlpStream.cs | Uses RlpHelpers for prefix-length calc and length deserialization; centralizes throw helpers. |
| src/Nethermind/Nethermind.Serialization.Rlp/RlpStream.cs | Adds PeekPrefixLength, switch-based PeekNextRlpLength, and helper-based length deserialization; refactors long string/list logic. |
| src/Nethermind/Nethermind.Serialization.Rlp/RlpHelpers.cs | New helper class providing branchless prefix calc, shared DeserializeLengthRef, and throw helpers. |
| src/Nethermind/Nethermind.Serialization.Rlp/Rlp.cs | Applies the same optimizations to ValueDecoderContext, replacing tuple-based peeks and manual length reads with helpers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Co-Authored-By: benaadams <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
6283097 to
f0c92c4
Compare
Good to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
This PR applies the performance optimizations from PR #9195 to
RlpStreamandRlp.ValueDecoderContextclasses, and introduces shared helper code to eliminate duplication between all three RLP processing implementations.Key Optimizations Applied
1. Branchless Prefix Length Calculation
Replaced conditional logic with bit manipulation for calculating RLP prefix lengths:
2. Switch Expression Optimizations
Converted if/else chains to switch expressions for better compiler optimization:
3. Optimized Method Separation
Split complex logic into specialized methods marked with
[MethodImpl(MethodImplOptions.NoInlining)]for better cache locality and JIT optimization of hot paths.4. Shared Helper Code
Created
RlpHelpersclass to eliminate code duplication:CalculatePrefixLength()- Branchless prefix calculationDeserializeLengthRef()- Optimized length deserialization5. Improved Bounds Checking
Replaced range checks with more efficient unsigned comparisons:
6. Optimized SkipItem Implementation
Simplified item skipping to use single method call instead of tuple destructuring:
Impact
RlpHelpersVerification
The optimizations maintain identical behavior while providing better performance characteristics for RLP processing, which is critical for Ethereum block and transaction parsing.
Fixes #9207.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
aka.mscurl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.