perf: fold/map/filter optimization#7022
Merged
federico-stacks merged 15 commits intostacks-network:developfrom Apr 15, 2026
Merged
perf: fold/map/filter optimization#7022federico-stacks merged 15 commits intostacks-network:developfrom
federico-stacks merged 15 commits intostacks-network:developfrom
Conversation
Signed-off-by: Jacinta Ferrant <236437600+jacinta-stacks@users.noreply.github.com>
Signed-off-by: Jacinta Ferrant <236437600+jacinta-stacks@users.noreply.github.com>
… into chore/fold-map-filter-skip-eval-roundtrip
… into chore/fold-map-filter-skip-eval-roundtrip
federico-stacks
commented
Mar 24, 2026
Coverage Report for CI Build 24402514996Coverage decreased (-0.06%) to 85.655%Details
Uncovered Changes
Coverage Regressions1945 previously-covered lines in 65 files lost coverage.
Coverage Stats
💛 - Coveralls |
federico-stacks
commented
Mar 24, 2026
5 tasks
jcnelson
previously approved these changes
Apr 6, 2026
Member
jcnelson
left a comment
There was a problem hiding this comment.
LGTM, as long as we leave this comment unaddressed (since it can be handled in a follow-up PR #7068): https://github.com/stacks-network/stacks-core/pull/7022/changes#r2980910603
Merged
via the queue into
stacks-network:develop
with commit Apr 15, 2026
cc33808
331 of 336 checks passed
5 tasks
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 PR revives the work done in this #6955.
In short here what it does:
fold,map, andfilterwere wrapping every sequence element in aSymbolicExpressiononly to immediately unwrap it again insideeval. This change eliminates that round-trip with a lazySequenceIteriterator and a newapply_evaluatedfunction that acceptsValues directly.foldandmap, ~2–7% fasterfilterHere the original description and benchmarking:
special_fold,special_map, andspecial_filterpreviously converted each sequence element into aSymbolicExpressionwrapper viaatom_values(), then fed those wrappers toapply(), which calledeval()on each one to then unwrap them BACK to aValue. Per iteration this meant:SymbolicExpression::atom_value(v)allocation (wraps theValue)eval()call that immediately returns the wrapped value (no-op work)fold/map: an intermediateVec<SymbolicExpression>holding all N wrappers before the first step begins. For afoldover a 2000-element list, that is 2000 unnecessary heap allocations and 2000 no-op eval round-trips per call.Added
SequenceIter, a lazy owned iterator over sequence elements. Changed the predicate inretain_valuesto remove the internalSymbolicExpression::atom_value()and addedapply_evaluated(..)to take pre-evaluatedValue's directly, skipping theevalpass entirely.Added
clarity/benches/sequence_higher_order.rswith end-to-end regression benchmarks forfold,map, andfilterat list sizes 100 / 500 / 2000.Baseline:
feat/variable-lookup-by-ref. (To rerun:cargo bench --bench sequence_higher_order -p clarity)fold: sum a list of integersmap: increment every elementfilter: keep even elementsfoldandmapsee a consistent ~7–8% improvement across all sizes because they use the new IntoIterator path end-to-end.filtersees a smaller gain (~2–7%) becauseretain_valuesstill iterates by index internally (see otherretain_valuesPR for further improvements); the saving comes only from removing theSymbolicExpressionwrap andevalround-trip per predicate call.The improvement is uniform across list sizes (per-element overhead is eliminated).
Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/property-testing.md)rpc/openapi.yamlfor RPC endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepo