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

Memory metering #1653

Merged
merged 405 commits into from
May 16, 2022
Merged

Memory metering #1653

merged 405 commits into from
May 16, 2022

Conversation

turbolent
Copy link
Member

Closes dapperlabs/cadence-private-issues#36

Huge shout-out to @SupunS @dsainati1 @robert-e-davidson3 👏 👏 👏


  • 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

SupunS and others added 30 commits March 16, 2022 12:42
Atree 0.3.0 uses new versions of CBOR and CircleHash:

- fxamacker/cbor [feature/stream-mode branch] to
  March 13 commit 12f5cb4b5eb0efcd590d323ff6a292a6d4f9e36c

- fxamacker/circlehash from 0.2.0 to 0.3.0
Port bumping onflow/atree from 0.2.0 to 0.3.0
* Memory metering for boolean
* Memory metering for nil
* Memory metering for VoidValue
* Memory metering for CharacterValue
* Memory metering for TypeValue
* memory metering for StorageReferenceValue
* memory metering for EphemeralReferenceValue
* memory metering for AddressValue
* Clone() method does not need to meter memory
* memory metering for PathValue
* memory metering for LinkValue
* use EmptyTypeValue where possible
* UseConstantValue is now a function not a method
* return NewNilValue instead of nil for bad paths
* Add memory metering tests for importing simple types
* AddressValue uses constant memory
* add TODO for future TypeValue work
* add many tests and some fixes
* simplest script has Void as well as InterpretedFunction
Co-authored-by: Bastian Müller <[email protected]>
Co-authored-by: robert <[email protected]>
Co-authored-by: Supun Setunga <[email protected]>
* address comments in prev PR

* meter link creation when atree validation is off

Co-authored-by: robert <[email protected]>
Refactor to meter address value before creation, whenever possible
@turbolent turbolent requested a review from SupunS as a code owner May 16, 2022 20:37
@turbolent turbolent self-assigned this May 16, 2022
@@ -88,6 +88,19 @@ to the `prepare` phase of the transaction.

let keys: AuthAccount.Keys

// Key management
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to include the public key API changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR just reverts the removal of the deprecated functions. This documentation should have been added back to master already before, but it seems like it wasn't

@github-actions
Copy link

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit bddd08f
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.

Results

old.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2128µs ± 7%127µs ± 8%~(p=0.456 n=7+7)
ContractInterfaceFungibleToken-238.5µs ± 5%38.8µs ±12%~(p=0.628 n=6+7)
InterpretRecursionFib-22.62ms ± 5%2.85ms ±12%+8.49%(p=0.014 n=6+7)
NewInterpreter/new_interpreter-21.09µs ± 3%1.11µs ±27%~(p=0.234 n=6+7)
NewInterpreter/new_sub-interpreter-22.21µs ± 7%2.23µs ± 6%~(p=0.818 n=6+6)
ParseArray-27.15ms ± 2%8.55ms ± 8%+19.59%(p=0.001 n=7+7)
ParseDeploy/byte_array-211.4ms ±13%12.8ms ± 8%+11.47%(p=0.007 n=7+7)
ParseDeploy/decode_hex-21.11ms ± 3%1.16ms ±11%~(p=0.710 n=7+7)
ParseInfix-26.22µs ± 4%7.64µs ± 4%+22.90%(p=0.001 n=7+6)
QualifiedIdentifierCreation/One_level-22.07ns ± 0%2.07ns ± 0%~(p=0.429 n=7+6)
QualifiedIdentifierCreation/Three_levels-2132ns ± 3%132ns ± 8%~(p=0.628 n=6+7)
RuntimeFungibleTokenTransfer-21.15ms ±23%1.17ms ±28%~(p=0.535 n=7+7)
RuntimeResourceDictionaryValues-26.43ms ± 5%6.60ms ± 3%~(p=0.073 n=7+7)
Transfer-281.8ns ± 5%84.7ns ± 5%~(p=0.053 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-266.3kB ± 0%66.3kB ± 0%+0.12%(p=0.001 n=6+7)
ContractInterfaceFungibleToken-226.7kB ± 0%26.7kB ± 0%+0.30%(p=0.001 n=7+6)
InterpretRecursionFib-21.14MB ± 0%1.25MB ± 0%+9.40%(p=0.001 n=6+7)
NewInterpreter/new_interpreter-2848B ± 0%872B ± 0%+2.83%(p=0.001 n=7+7)
NewInterpreter/new_sub-interpreter-21.34kB ± 0%1.38kB ± 0%+3.59%(p=0.001 n=7+7)
ParseArray-22.92MB ± 2%2.93MB ± 2%~(p=0.128 n=7+7)
ParseDeploy/byte_array-24.26MB ± 3%4.28MB ± 3%~(p=0.259 n=7+7)
ParseDeploy/decode_hex-2213kB ± 0%213kB ± 0%~(p=0.309 n=7+7)
ParseInfix-22.12kB ± 0%2.14kB ± 0%+0.78%(p=0.001 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2234kB ± 0%236kB ± 0%+1.12%(p=0.001 n=7+6)
RuntimeResourceDictionaryValues-22.24MB ± 0%2.24MB ± 0%+0.09%(p=0.026 n=7+7)
Transfer-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
ContractInterfaceFungibleToken-2460 ± 0%460 ± 0%~(all equal)
InterpretRecursionFib-223.8k ± 0%23.8k ± 0%~(all equal)
NewInterpreter/new_interpreter-213.0 ± 0%12.0 ± 0%−7.69%(p=0.001 n=7+7)
NewInterpreter/new_sub-interpreter-240.0 ± 0%40.0 ± 0%~(all equal)
ParseArray-270.0k ± 0%70.0k ± 0%~(p=0.213 n=7+7)
ParseDeploy/byte_array-2105k ± 0%105k ± 0%~(p=0.592 n=7+7)
ParseDeploy/decode_hex-279.0 ± 0%79.0 ± 0%~(all equal)
ParseInfix-266.0 ± 0%66.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-24.57k ± 0%4.58k ± 0%+0.18%(p=0.001 n=7+7)
RuntimeResourceDictionaryValues-237.6k ± 0%37.6k ± 0%+0.02%(p=0.003 n=7+5)
Transfer-21.00 ± 0%1.00 ± 0%~(all equal)
 

@@ -85,6 +85,7 @@ func ByteValueToByte(element Value) (byte, error) {
return b, nil
}

// TODO: meter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be safe to remove this todo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #1653 (08b93d4) into master (bddd08f) will increase coverage by 1.66%.
The diff coverage is 84.97%.

@@            Coverage Diff             @@
##           master    #1653      +/-   ##
==========================================
+ Coverage   74.78%   76.45%   +1.66%     
==========================================
  Files         288      291       +3     
  Lines       55418    60678    +5260     
==========================================
+ Hits        41444    46389    +4945     
- Misses      12481    12677     +196     
- Partials     1493     1612     +119     
Flag Coverage Δ
unittests 76.45% <84.97%> (+1.66%) ⬆️

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

Impacted Files Coverage Δ
fixedpoint/check.go 82.50% <ø> (ø)
fuzz.go 0.00% <0.00%> (ø)
helpers.go 0.00% <ø> (ø)
runtime/ast/visitor.go 42.85% <0.00%> (ø)
runtime/common/repllocation.go 63.33% <0.00%> (-3.34%) ⬇️
runtime/interpreter/value.go 71.39% <ø> (+7.73%) ⬆️
runtime/interpreter/variable.go 100.00% <ø> (ø)
runtime/interpreter/variable_activations.go 66.33% <ø> (+4.11%) ⬆️
runtime/interpreter/walk.go 62.50% <ø> (ø)
runtime/literal.go 86.29% <ø> (+1.46%) ⬆️
... and 188 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bddd08f...08b93d4. Read the comment docs.

Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 🎉 🎉

@turbolent turbolent merged commit de17b89 into master May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants