New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(clarity): Replace Vec::new()
and vec![]
#4408
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #4408 +/- ##
===========================================
- Coverage 83.41% 71.26% -12.15%
===========================================
Files 448 448
Lines 323911 323925 +14
===========================================
- Hits 270182 230850 -39332
- Misses 53729 93075 +39346
... and 218 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
763548c
to
345a822
Compare
204b85f
to
345a822
Compare
clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs
Outdated
Show resolved
Hide resolved
345a822
to
9ff45c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
Replace instances of
Vec::new
andvec![]
withvec::with_capacity()
or.map()
/.collect()
whenever possible in Clarity code. This should help reduce the number of calls to alloc and reallocCurrently showing about a 2% improvement:
Applicable issues
Additional info (benefits, drawbacks, caveats)
===> PLEASE READ BEFORE REVIEWING <===
There are several places where, the loop over
Vec::push()
would exit early in the event of an error. Since we now allocate before the loop usingVec::with_capacity()
, this can lead to allocating more memory than would otherwise have been allocated in an error condition. This would only be a problem if user input could somehow force arbitrarily large allocations, resulting in a DoS attack by OOM. I don't think that is the case for any of the code I have modified, but keep it in mind while reviewingAlso there may be some places where pushing to the
Vec
is an uncommon event, or only done in case of an error. In these cases maybe pre-allocating memory does not make senseChecklist
docs/rpc/openapi.yaml
andrpc-endpoints.md
for v2 endpoints,event-dispatcher.md
for new events)clarity-benchmarking
repobitcoin-tests.yml