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

Optimize ByteSize functions for 7 Value types #1299

Merged
merged 1 commit into from
Dec 8, 2021

Conversation

fxamacker
Copy link
Member

@fxamacker fxamacker commented Dec 6, 2021

Closes #1259

Description

ByteSize() of some types were obtained by encoding the values to CBOR and getting the resulting data size.

This optimization computes the data size without encoding.

Optimized ByteSize() for the following Value types:

  • IntValue
  • Int128Value
  • Int256Value
  • UIntValue
  • UInt128Value
  • UInt256Value
  • PathValue

Caveats

These were not optimized yet because it would increase code maintenance.

  • TypeValue
  • CapabilityValue
  • LinkValue

  • 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

Optimized ByteSize() for the following Value types:
- IntValue
- Int128Value
- Int256Value
- UIntValue
- UInt128Value
- UInt256Value
- PathValue
@fxamacker fxamacker requested a review from turbolent December 6, 2021 15:38
@fxamacker fxamacker self-assigned this Dec 6, 2021
@fxamacker fxamacker requested a review from SupunS as a code owner December 6, 2021 15:38
@codecov-commenter
Copy link

Codecov Report

Merging #1299 (87519cb) into master (b3c99f7) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1299   +/-   ##
=======================================
  Coverage   77.17%   77.18%           
=======================================
  Files         279      279           
  Lines       35791    35796    +5     
=======================================
+ Hits        27623    27628    +5     
  Misses       7081     7081           
  Partials     1087     1087           
Flag Coverage Δ
unittests 77.18% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
runtime/interpreter/encode.go 65.70% <100.00%> (+0.45%) ⬆️
runtime/interpreter/value.go 80.11% <100.00%> (ø)

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 b3c99f7...87519cb. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Dec 6, 2021

Cadence Benchstat comparison

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

Results

old.txtnew.txt
time/opdelta
RuntimeFungibleTokenTransfer-21.49ms ±18%1.47ms ±16%~(p=0.805 n=7+7)
ParseArray-224.0ms ± 1%23.8ms ± 2%~(p=0.180 n=6+6)
ParseInfix-225.7µs ± 1%25.7µs ± 1%~(p=0.902 n=7+7)
ParseDeploy/byte_array-236.3ms ± 1%36.3ms ± 1%~(p=0.805 n=7+7)
ParseDeploy/decode_hex-21.44ms ± 4%1.42ms ± 0%~(p=0.432 n=7+5)
ParseFungibleToken-2493µs ± 1%489µs ± 2%~(p=0.138 n=6+7)
QualifiedIdentifierCreation/One_level-23.21ns ± 0%3.21ns ± 1%~(p=0.754 n=6+7)
QualifiedIdentifierCreation/Three_levels-2167ns ± 1%167ns ± 2%~(p=0.702 n=6+7)
NewInterpreter/new_interpreter-21.22µs ± 2%1.21µs ± 1%~(p=0.120 n=7+7)
NewInterpreter/new_sub-interpreter-22.27µs ± 1%2.25µs ± 1%~(p=0.050 n=6+7)
CheckContractInterfaceFungibleTokenConformance-2160µs ± 1%159µs ± 1%−0.90%(p=0.035 n=6+7)
InterpretRecursionFib-22.82ms ± 1%2.78ms ± 0%−1.31%(p=0.004 n=6+5)
ContractInterfaceFungibleToken-249.4µs ± 2%48.3µs ± 2%−2.08%(p=0.014 n=6+7)
RuntimeResourceDictionaryValues-217.9ms ± 3%17.0ms ± 2%−5.01%(p=0.001 n=7+7)
 
alloc/opdelta
RuntimeFungibleTokenTransfer-2238kB ± 0%238kB ± 0%~(p=0.736 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
ContractInterfaceFungibleToken-226.5kB ± 0%26.5kB ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-265.7kB ± 0%65.7kB ± 0%~(p=1.000 n=7+7)
NewInterpreter/new_interpreter-2720B ± 0%720B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.11kB ± 0%1.11kB ± 0%~(all equal)
InterpretRecursionFib-21.24MB ± 0%1.24MB ± 0%~(p=0.192 n=7+7)
RuntimeResourceDictionaryValues-24.34MB ± 0%4.04MB ± 0%−7.01%(p=0.001 n=7+7)
 
allocs/opdelta
RuntimeFungibleTokenTransfer-24.53k ± 0%4.53k ± 0%~(p=1.000 n=7+7)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
ContractInterfaceFungibleToken-2457 ± 0%457 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
NewInterpreter/new_interpreter-211.0 ± 0%11.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-232.0 ± 0%32.0 ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
RuntimeResourceDictionaryValues-2108k ± 0%102k ± 0%−5.57%(p=0.001 n=7+7)
 

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.

Looks good!

Would this require a storage migration?

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.

Very nice! Thank you for optimizing this 👍

@fxamacker
Copy link
Member Author

Would this require a storage migration?

@SupunS Great question! I should've mentioned it. No, it doesn't require migration, just optimization under the hood.

@fxamacker fxamacker merged commit bb225e4 into master Dec 8, 2021
@turbolent turbolent deleted the fxamacker/optimize-bytesize branch March 1, 2022 00:36
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.

Optimize ByteSize
4 participants