Repository navigation
perf: add Token::decode_many_from for batch decoding - #1089
Merged
Merged
Conversation
Add an unsafe decode_many_from method to the Token trait that writes decoded tokens directly into an uninitialized buffer. The default implementation loops over decode_from with a drop guard for safety. WordToken overrides this to perform a single memcpy via copy_nonoverlapping instead of N individual word copies, reducing the operation from O(N) decode_from calls (each with a bounds check) to a single bounds check + memcpy. Both DynSeqToken and FixedSeqToken now use decode_many_from.
This reverts commit 94d9a02.
WordToken overrides this to reinterpret &[WordToken] as &[Word] and call extend_from_slice, replacing N individual Vec::push calls with a single memcpy. FixedSeqToken and DynSeqToken use head_append_many in their encode_sequence and head_append for non-dynamic inner tokens.
mattsse
approved these changes
Mar 24, 2026
This reverts commit 07a3054.
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.
Adds an
unsafe decode_many_frommethod to theTokentrait that writes decoded tokens directly into an uninitialized buffer (&mut [MaybeUninit<Self>]). The default implementation loops overdecode_fromwith a drop guard for panic safety.WordTokenoverrides this to perform a singlecopy_nonoverlappinginstead of N individualtake_word+ copy calls, reducing the operation from O(N)decode_fromcalls (each with a bounds check and 32-byte copy) to one bounds check + one memcpy.Both
DynSeqTokenandFixedSeqTokennow usedecode_many_fromfor their sequence decoding.Benchmarks
Decoding an
authorizeKeycalldata payload with offset aliasing (N sharedCallScopeentries, each containing Nbytes4selectors):End-to-end (hyperfine, all sizes combined): 1.30x faster.