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

Refactor memory kinds and memory usages #1667

Merged
merged 6 commits into from
May 20, 2022
Merged

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented May 20, 2022

Description

This PR mostly does some cleanup on the memory kinds and usages. This inlude:

  • Removing MemoryKindCadenceDictionarySize, as it is not used at FVM (zero weight)
  • Predefining all the constant memory usages. Thus, common.UseConstantMemory() is no longer used, and hence removed.
  • Renaming interpreter value-related memory kinds and usages by appending "Value", to have a unified naming convention.
  • Move some memory metering tests to correct files.

  • 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 SupunS self-assigned this May 20, 2022
@@ -382,106 +382,6 @@ func (testMemoryError) Error() string {
return "memory limit exceeded"
}

func TestMemoryMeteringErrors(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to the relevant runtime_memory_metering_test.go file

@codecov
Copy link

codecov bot commented May 20, 2022

Codecov Report

Merging #1667 (c1bb4e8) into master (37aea92) will decrease coverage by 0.01%.
The diff coverage is 88.53%.

@@            Coverage Diff             @@
##           master    #1667      +/-   ##
==========================================
- Coverage   76.50%   76.49%   -0.02%     
==========================================
  Files         291      291              
  Lines       61019    60977      -42     
==========================================
- Hits        46684    46645      -39     
+ Misses      12723    12722       -1     
+ Partials     1612     1610       -2     
Flag Coverage Δ
unittests 76.49% <88.53%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
runtime/common/memorykind_string.go 40.00% <ø> (ø)
types.go 78.20% <73.13%> (ø)
runtime/common/metering.go 91.30% <100.00%> (-0.70%) ⬇️
runtime/interpreter/decode.go 46.92% <100.00%> (ø)
runtime/interpreter/function.go 63.63% <100.00%> (ø)
runtime/interpreter/primitivestatictype.go 81.20% <100.00%> (ø)
runtime/interpreter/simplecompositevalue.go 63.90% <100.00%> (ø)
runtime/interpreter/statictype.go 81.88% <100.00%> (ø)
runtime/interpreter/value.go 71.82% <100.00%> (ø)
values.go 65.82% <100.00%> (-0.08%) ⬇️
... and 3 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 37aea92...c1bb4e8. Read the comment docs.

@github-actions
Copy link

github-actions bot commented May 20, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 37aea92
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-2146µs ± 7%145µs ± 4%~(p=0.710 n=7+7)
ContractInterfaceFungibleToken-245.9µs ±12%45.0µs ± 4%~(p=1.000 n=7+7)
InterpretRecursionFib-23.00ms ± 4%3.07ms ± 0%~(p=0.181 n=7+6)
NewInterpreter/new_interpreter-21.22µs ± 3%1.29µs ± 6%+5.67%(p=0.038 n=7+7)
NewInterpreter/new_sub-interpreter-22.41µs ± 4%2.49µs ± 5%~(p=0.098 n=6+7)
ParseArray-28.93ms ± 6%8.88ms ± 5%~(p=0.710 n=7+7)
ParseDeploy/byte_array-213.2ms ± 7%13.0ms ± 1%~(p=0.073 n=7+7)
ParseDeploy/decode_hex-21.20ms ± 3%1.19ms ± 1%~(p=0.589 n=6+6)
ParseFungibleToken/With_memory_metering-2221µs ± 4%209µs ± 1%−5.64%(p=0.001 n=7+6)
ParseFungibleToken/Without_memory_metering-2164µs ± 1%164µs ± 2%~(p=0.456 n=7+7)
ParseInfix-27.67µs ± 1%7.66µs ± 2%~(p=0.366 n=6+7)
QualifiedIdentifierCreation/One_level-22.68ns ± 0%2.35ns ± 0%−12.47%(p=0.000 n=6+7)
QualifiedIdentifierCreation/Three_levels-2149ns ± 2%144ns ± 1%−3.12%(p=0.001 n=6+7)
RuntimeFungibleTokenTransfer-21.31ms ±22%1.24ms ±29%~(p=0.259 n=7+7)
RuntimeResourceDictionaryValues-27.23ms ± 4%7.17ms ± 3%~(p=0.710 n=7+7)
Transfer-293.8ns ± 1%93.5ns ± 1%~(p=0.684 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-266.3kB ± 0%66.3kB ± 0%~(p=0.706 n=7+7)
ContractInterfaceFungibleToken-226.7kB ± 0%26.7kB ± 0%+0.00%(p=0.001 n=7+6)
InterpretRecursionFib-21.25MB ± 0%1.25MB ± 0%~(all equal)
NewInterpreter/new_interpreter-2872B ± 0%872B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.38kB ± 0%1.38kB ± 0%~(all equal)
ParseArray-22.95MB ± 2%2.95MB ± 2%~(p=0.710 n=7+7)
ParseDeploy/byte_array-24.31MB ± 3%4.19MB ± 0%−2.63%(p=0.015 n=7+6)
ParseDeploy/decode_hex-2213kB ± 0%213kB ± 0%~(p=0.799 n=7+7)
ParseFungibleToken/With_memory_metering-236.3kB ± 0%36.3kB ± 0%~(p=0.311 n=7+7)
ParseFungibleToken/Without_memory_metering-236.3kB ± 0%36.3kB ± 0%~(p=0.554 n=7+7)
ParseInfix-22.14kB ± 0%2.14kB ± 0%~(p=0.592 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2237kB ± 1%237kB ± 0%~(p=1.000 n=7+7)
RuntimeResourceDictionaryValues-22.24MB ± 0%2.24MB ± 0%~(p=0.730 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-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-240.0 ± 0%40.0 ± 0%~(all equal)
ParseArray-270.0k ± 0%70.0k ± 0%~(p=1.000 n=7+7)
ParseDeploy/byte_array-2105k ± 0%105k ± 0%~(p=1.000 n=7+7)
ParseDeploy/decode_hex-279.0 ± 0%79.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-21.06k ± 0%1.06k ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-21.06k ± 0%1.06k ± 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.58k ± 0%4.58k ± 0%~(p=0.494 n=7+7)
RuntimeResourceDictionaryValues-237.6k ± 0%37.6k ± 0%~(p=0.716 n=7+7)
Transfer-21.00 ± 0%1.00 ± 0%~(all equal)
 

@SupunS SupunS marked this pull request as ready for review May 20, 2022 20:04
@SupunS SupunS requested a review from robert-e-davidson3 May 20, 2022 20:04
Copy link
Contributor

@robert-e-davidson3 robert-e-davidson3 left a comment

Choose a reason for hiding this comment

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

I like how you replaced UseConstantMemory with global constants.

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

🧹

@SupunS SupunS merged commit 7b9689d into master May 20, 2022
@SupunS SupunS deleted the supun/cleanup-memorykinds branch May 20, 2022 20:46
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.

3 participants