perf: drop per-element copies in Clarity value deserialization#7426
Merged
francesco-stacks merged 4 commits intoJul 22, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improves performance of Clarity Value deserialization by eliminating avoidable per-element allocations/copies while preserving accepted/rejected bytes and resulting values, and adds targeted tests to pin correctness of the new fast paths.
Changes:
- Stream
construct_parent_list_type()/parent_list_type()entry-type computation via a shared fold iterator (with an equality fast-path). - Update the deserializer to mutate stack frames in place (avoid pop/re-push per element) and make
next_expected_type()return references instead of deep clones. - Add tests for
least_supertype_v2_1idempotence and for tuple truncation during unwind, plus a changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| clarity-types/src/types/signatures.rs | Streams list entry-type folding via a shared iterator-based helper to avoid per-element type collection. |
| clarity-types/src/types/serialization.rs | Removes per-element frame pop/re-push and avoids per-element deep clones of expected types during deserialization. |
| clarity-types/src/tests/types/signatures.rs | Adds idempotence/property-style coverage ensuring the new equality fast-path is sound and that streamed/collected list type construction matches. |
| clarity-types/src/tests/types/serialization.rs | Adds a regression test for EOF while reading the next tuple key during unwind. |
| changelog.d/clarity-value-deser-perf.changed | Documents the deserialization performance improvement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rob-stacks
approved these changes
Jul 22, 2026
Merged
via the queue into
stacks-network:develop
with commit Jul 22, 2026
91f4c11
219 of 222 checks passed
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.
Description
This removes the main memory and CPU overheads in Clarity value deserialization. No behavior changes...same bytes accepted and rejected, same resulting values
Three changes:
construct_parent_list_typeno longer collects aTypeSignaturefor every list element before computing the entry type. It folds while iterating, and skips the fold when the next type equals the accumulator (safe becauseleast_supertype_v2_1(T, T) == T, pinned by a new test).next_expected_typereturned a deep clone of the expected type for every element. It now returns a reference.On a 1M-element bool list (counting-allocator harness, vs current develop): untyped reads go from 141 MiB / 62 ms to 61 MiB / 28 ms. Typed reads are 16-21% faster with the same peak.
Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/property-testing.md)changelog.d/README.md)rpc/openapi.yamlfor RPC endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepo