Skip to content
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

Avoid unnecessary slice allocations #2191

Merged
merged 2 commits into from
Dec 12, 2022

Conversation

turbolent
Copy link
Member

Description

Do not unnecessarily allocate empty slices.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@turbolent turbolent requested a review from a team December 9, 2022 22:31
@turbolent turbolent self-assigned this Dec 9, 2022
@codecov
Copy link

codecov bot commented Dec 9, 2022

Codecov Report

Merging #2191 (94be3f1) into master (29fd837) will decrease coverage by 0.01%.
The diff coverage is 82.61%.

@@            Coverage Diff             @@
##           master    #2191      +/-   ##
==========================================
- Coverage   77.60%   77.58%   -0.02%     
==========================================
  Files         309      309              
  Lines       65289    65406     +117     
==========================================
+ Hits        50666    50747      +81     
- Misses      12852    12880      +28     
- Partials     1771     1779       +8     
Flag Coverage Δ
unittests 77.58% <82.61%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/interpreter/decode.go 46.28% <24.13%> (+0.08%) ⬆️
runtime/interpreter/statictype.go 78.35% <28.35%> (-4.77%) ⬇️
runtime/interpreter/interpreter_invocation.go 91.66% <75.67%> (+0.40%) ⬆️
runtime/interpreter/interpreter.go 89.34% <97.05%> (+0.05%) ⬆️
runtime/interpreter/conversion.go 92.75% <100.00%> (+0.95%) ⬆️
runtime/interpreter/interpreter_expression.go 86.77% <100.00%> (+0.22%) ⬆️
runtime/sema/check_array_expression.go 100.00% <100.00%> (ø)
runtime/sema/check_dictionary_expression.go 100.00% <100.00%> (ø)
runtime/sema/check_invocation_expression.go 98.21% <100.00%> (+0.03%) ⬆️
runtime/sema/check_transaction_declaration.go 84.61% <100.00%> (+0.32%) ⬆️
... and 14 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link

github-actions bot commented Dec 9, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 29fd837
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -benchmem -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2109µs ± 0%108µs ± 0%−0.88%(p=0.002 n=6+6)
ContractInterfaceFungibleToken-237.5µs ± 1%37.4µs ± 1%~(p=0.421 n=6+7)
InterpretRecursionFib-22.45ms ± 2%2.44ms ± 1%~(p=0.318 n=7+7)
NewInterpreter/new_interpreter-21.09µs ± 1%1.08µs ± 0%−0.83%(p=0.002 n=7+7)
NewInterpreter/new_sub-interpreter-2571ns ± 0%570ns ± 1%~(p=0.475 n=7+7)
ParseArray-27.50ms ± 1%7.68ms ± 4%~(p=0.053 n=7+7)
ParseDeploy/byte_array-211.5ms ± 3%11.5ms ± 5%~(p=1.000 n=7+7)
ParseDeploy/decode_hex-21.21ms ± 1%1.20ms ± 1%~(p=0.366 n=6+7)
ParseFungibleToken/With_memory_metering-2181µs ± 0%184µs ± 2%+1.55%(p=0.022 n=6+7)
ParseFungibleToken/Without_memory_metering-2141µs ± 0%143µs ± 3%~(p=0.053 n=7+7)
ParseInfix-27.19µs ± 7%6.99µs ± 1%~(p=0.628 n=7+6)
QualifiedIdentifierCreation/One_level-22.41ns ± 0%2.41ns ± 0%−0.07%(p=0.045 n=6+7)
QualifiedIdentifierCreation/Three_levels-2117ns ± 1%115ns ± 1%−1.57%(p=0.001 n=7+6)
RuntimeFungibleTokenTransfer-2576µs ±24%493µs ±29%~(p=0.073 n=7+7)
RuntimeResourceDictionaryValues-25.05ms ± 1%5.07ms ± 0%~(p=0.073 n=7+6)
RuntimeScriptNoop-216.4µs ±29%17.3µs ±24%~(p=0.383 n=7+7)
SuperTypeInference/arrays-2292ns ± 4%282ns ± 1%−3.23%(p=0.001 n=7+6)
SuperTypeInference/composites-2130ns ± 0%130ns ± 0%~(p=0.600 n=6+6)
SuperTypeInference/integers-292.7ns ± 0%90.5ns ± 0%−2.45%(p=0.001 n=7+7)
ValueIsSubtypeOfSemaType-286.2ns ± 3%86.9ns ± 1%~(p=0.245 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-248.8kB ± 0%48.7kB ± 0%−0.10%(p=0.001 n=7+7)
ContractInterfaceFungibleToken-222.9kB ± 0%22.9kB ± 0%~(all equal)
InterpretRecursionFib-21.00MB ± 0%1.00MB ± 0%~(p=0.636 n=5+7)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-2200B ± 0%200B ± 0%~(all equal)
ParseArray-22.70MB ± 2%2.78MB ± 5%~(p=0.165 n=7+7)
ParseDeploy/byte_array-24.18MB ± 2%4.09MB ± 0%~(p=0.343 n=7+5)
ParseDeploy/decode_hex-2214kB ± 0%214kB ± 0%~(p=0.106 n=6+7)
ParseFungibleToken/With_memory_metering-229.2kB ± 0%29.2kB ± 0%~(p=0.286 n=7+7)
ParseFungibleToken/Without_memory_metering-229.2kB ± 0%29.2kB ± 0%~(p=0.580 n=7+7)
ParseInfix-21.92kB ± 0%1.92kB ± 0%~(p=0.103 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2102kB ± 1%101kB ± 0%−0.73%(p=0.011 n=7+7)
RuntimeResourceDictionaryValues-22.28MB ± 0%2.28MB ± 0%~(p=0.902 n=7+7)
RuntimeScriptNoop-26.77kB ± 0%6.78kB ± 1%~(p=0.971 n=7+7)
SuperTypeInference/arrays-296.0B ± 0%96.0B ± 0%~(all equal)
SuperTypeInference/composites-20.00B 0.00B ~(all equal)
SuperTypeInference/integers-20.00B 0.00B ~(all equal)
ValueIsSubtypeOfSemaType-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-2797 ± 0%794 ± 0%−0.38%(p=0.001 n=7+7)
ContractInterfaceFungibleToken-2363 ± 0%363 ± 0%~(all equal)
InterpretRecursionFib-218.9k ± 0%18.9k ± 0%~(all equal)
NewInterpreter/new_interpreter-213.0 ± 0%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-24.00 ± 0%4.00 ± 0%~(all equal)
ParseArray-259.6k ± 0%59.6k ± 0%~(p=0.245 n=6+7)
ParseDeploy/byte_array-289.4k ± 0%89.4k ± 0%~(p=0.098 n=7+6)
ParseDeploy/decode_hex-264.0 ± 0%64.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-2779 ± 0%779 ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-2779 ± 0%779 ± 0%~(all equal)
ParseInfix-248.0 ± 0%48.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
RuntimeFungibleTokenTransfer-21.97k ± 0%1.96k ± 0%−0.34%(p=0.001 n=7+7)
RuntimeResourceDictionaryValues-236.9k ± 0%36.9k ± 0%−0.01%(p=0.001 n=7+7)
RuntimeScriptNoop-298.0 ± 0%98.0 ± 0%~(all equal)
SuperTypeInference/arrays-23.00 ± 0%3.00 ± 0%~(all equal)
SuperTypeInference/composites-20.00 0.00 ~(all equal)
SuperTypeInference/integers-20.00 0.00 ~(all equal)
ValueIsSubtypeOfSemaType-21.00 ± 0%1.00 ± 0%~(all equal)
 

@turbolent turbolent merged commit 708d10f into master Dec 12, 2022
@turbolent turbolent deleted the bastian/avoid-unnecessary-slice-allocations branch December 12, 2022 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants