perf: fast-path exact primitive vector decode#712
Merged
Conversation
Skip repeated type setup for vecs whose wire and expected element types are the same fixed-width primitive so large primitive arrays decode with less overhead.
Click to see raw report |
… vec fast path - Add Drop impl on Compound to reset primitive_vec_fast_path on drop, preventing fast-path state leaking on error/panic paths; reborrow self.de in VariantAccess methods to satisfy the compiler - Add comment explaining why deserialize_bool lives outside primitive_impl! - Add tests: nested Vec<Vec<i16>>, struct with vec field, mismatched Rust/wire type error path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
lwshang
approved these changes
Mar 15, 2026
lwshang
added a commit
that referenced
this pull request
Mar 18, 2026
When decoding a trailing/extra argument that is a primitive vector, `deserialize_ignored_any` relies on `expect_type`/`wire_type` being set to the element type. The fast path introduced in #712 skipped setting these, causing `deserialize_ignored_any` to see the outer `Vec<T>` type and attempt to decode a nested vector instead of a scalar, corrupting the byte stream. Fix: always set `expect_type`/`wire_type` to the element type before calling `seed.deserialize`, and only skip `add_cost(3)` in the fast path. The `primitive_impl!` macro checks `primitive_vec_fast_path` before touching these types, so normal decode performance is unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 tasks
lwshang
added a commit
that referenced
this pull request
Mar 18, 2026
## Summary - Fix decoding failure when a trailing/extra argument is a primitive vector (`vec int8/16/32/64`, `vec nat8/16/32/64`, `vec float32/64`, `vec bool`) - The fast-path optimization (#712) skipped setting `expect_type`/`wire_type` per element; `deserialize_ignored_any` then misidentified the element type and corrupted the byte stream - Fix: always set element types before calling `seed.deserialize`, skipping only the `add_cost(3)` call in the fast path - Release candid 0.10.26 ## Test plan - [ ] New regression test `primitive_vector_is_extra_args` in `tests/compatibility_vectors.rs` covers the exact failure scenario - [ ] All existing `compatibility_vectors` tests continue to pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Overview
Reduce repeated per-element type work when decoding primitive vectors.
Requirements
Preserve vector decoding semantics, including compatibility with extra trailing arguments.
Solution
Add an exact-primitive fast path for vector elements so deserialization can skip repeated type unrolling and checks when expected and wire element types already match. Add a compatibility test covering extra-args behavior.
Considerations
The optimization is limited to exact primitive matches and leaves the general decode path unchanged. Series-level benchmark context is tracked in #710.