perf(engine): remove serde(flatten) from execution payload types#3713
Merged
perf(engine): remove serde(flatten) from execution payload types#3713
Conversation
Replace derived Deserialize with manual impls using flat helper structs for ExecutionPayloadV2, V3, V4, ExecutionPayloadInputV2, and ExecutionPayloadEnvelopeV4. serde(flatten) forces deserialization through an intermediate serde_json::Map, causing double allocation of every field value (especially expensive for the transactions Vec<Bytes> and Bloom). The nested flatten chain (V3 -> V2 -> V1) made this 3 levels deep. The manual impls use a flat helper struct that serde generates an optimal field-order-aware deserializer for, avoiding the intermediate map entirely. Amp-Thread-ID: https://ampcode.com/threads/T-019c6ccb-3758-70a5-bfc4-c087afe44303 Co-authored-by: Amp <[email protected]>
mattsse
approved these changes
Feb 17, 2026
stevencartavia
approved these changes
Feb 17, 2026
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.
Summary
Remove
serde(flatten)from execution payload deserialization to eliminate the intermediateserde_json::Mapbuffering overhead.Motivation
serde(flatten)forces deserialization through an intermediateMap<String, Value>, causing double allocation of every field. ForExecutionPayloadV3, the flatten chain was 3 levels deep (V3 → V2 → V1), meaning every field — including the expensivetransactions: Vec<Bytes>andBloom— got parsed intoserde_json::Valuefirst, then re-deserialized into their actual types.This is on the hot path for
engine_newPayloadV3.What
serde(flatten)actually expands toFor
ExecutionPayloadV3which only has 2 own fields (blobGasUsed,excessBlobGas) + a flattenedExecutionPayloadV2, the derivedDeserializeexpanded to ~470 lines (viacargo expand). The critical overhead is in thevisit_mapimplementation:For a mainnet block with ~200 transactions, each transaction
Bytesblob gets:Content::String(String)(alloc Port RPC types from reth #1)Content::StringintoBytesviaFlatMapDeserializer(alloc Add a transports crate & initial Network abstraction #2)The
Bloom(512 hex chars) and allB256fields suffer the same double-parse.After this PR
The manual
Deserializeimpl uses a flat helper struct:serde generates an optimal field-order-aware deserializer for the flat struct — no intermediate
Contentbuffering, noFlatMapDeserializer, single-pass deserialization directly into target types.Changes
Deserializewith manual impls using flat helper structs for:ExecutionPayloadV2(was 1 flatten level)ExecutionPayloadV3(was 2 flatten levels)ExecutionPayloadV4(was 3 flatten levels)ExecutionPayloadInputV2(was 1 flatten level +deny_unknown_fields)ExecutionPayloadEnvelopeV4(was 1 flatten level)Serializewithserde(flatten)— serialization does not have the same overheadTesting
cargo test -p alloy-rpc-types-engine --features serde— all 55 tests pass including existing hive test vectors.Prompted by: mattsse