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

Improve constant-sized type parsing #1613

Merged
merged 2 commits into from
May 12, 2022

Conversation

turbolent
Copy link
Member

Description

Optimize parsing of the size in constant-sized types by directly checking for an integer literal.


  • 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

@github-actions
Copy link

github-actions bot commented Apr 29, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit f615bea
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-2189µs ± 4%188µs ± 4%~(p=0.836 n=7+6)
ContractInterfaceFungibleToken-253.8µs ± 6%53.5µs ± 7%~(p=0.710 n=7+7)
InterpretRecursionFib-23.42ms ± 9%3.37ms ± 7%~(p=0.318 n=7+7)
NewInterpreter/new_interpreter-21.50µs ± 5%1.46µs ± 4%~(p=0.181 n=7+6)
NewInterpreter/new_sub-interpreter-22.94µs ± 5%2.83µs ± 4%~(p=0.053 n=7+7)
ParseArray-217.7ms ±11%9.6ms ± 4%−46.13%(p=0.001 n=7+7)
ParseDeploy/byte_array-227.2ms ±11%14.2ms ± 3%−47.91%(p=0.001 n=7+6)
ParseDeploy/decode_hex-21.54ms ± 7%1.50ms ± 4%~(p=0.383 n=7+7)
ParseFungibleToken-2254µs ± 3%184µs ± 4%−27.54%(p=0.001 n=7+7)
ParseInfix-211.0µs ± 4%8.3µs ± 3%−24.11%(p=0.001 n=7+7)
QualifiedIdentifierCreation/One_level-23.40ns ± 5%3.43ns ± 5%~(p=0.620 n=7+7)
QualifiedIdentifierCreation/Three_levels-2186ns ± 7%182ns ± 4%~(p=0.456 n=7+7)
RuntimeFungibleTokenTransfer-21.57ms ±26%1.49ms ±27%~(p=0.165 n=7+7)
RuntimeResourceDictionaryValues-28.60ms ± 5%8.61ms ± 3%~(p=1.000 n=7+7)
Transfer-2114ns ± 7%111ns ± 5%~(p=0.318 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-266.3kB ± 0%66.3kB ± 0%~(all equal)
ContractInterfaceFungibleToken-226.7kB ± 0%26.7kB ± 0%~(p=1.000 n=7+7)
InterpretRecursionFib-21.14MB ± 0%1.14MB ± 0%~(p=0.462 n=7+7)
NewInterpreter/new_interpreter-2848B ± 0%848B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.34kB ± 0%1.34kB ± 0%~(all equal)
ParseArray-213.5MB ± 0%3.0MB ± 2%−77.98%(p=0.001 n=7+7)
ParseDeploy/byte_array-221.0MB ± 0%4.3MB ± 3%−79.43%(p=0.001 n=7+7)
ParseDeploy/decode_hex-2218kB ± 0%213kB ± 0%−2.07%(p=0.001 n=7+7)
ParseFungibleToken-2199kB ± 0%36kB ± 0%−81.78%(p=0.000 n=7+6)
ParseInfix-26.76kB ± 0%2.10kB ± 0%−68.87%(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-2273kB ± 0%234kB ± 0%−14.39%(p=0.001 n=7+6)
RuntimeResourceDictionaryValues-22.25MB ± 0%2.24MB ± 0%−0.51%(p=0.001 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%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-240.0 ± 0%40.0 ± 0%~(all equal)
ParseArray-270.0k ± 0%70.0k ± 0%−0.04%(p=0.003 n=7+5)
ParseDeploy/byte_array-2105k ± 0%105k ± 0%−0.02%(p=0.003 n=7+5)
ParseDeploy/decode_hex-286.0 ± 0%79.0 ± 0%−8.14%(p=0.001 n=7+7)
ParseFungibleToken-21.07k ± 0%1.06k ± 0%−1.12%(p=0.001 n=7+7)
ParseInfix-273.0 ± 0%66.0 ± 0%−9.59%(p=0.001 n=7+7)
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.57k ± 0%−0.19%(p=0.001 n=7+7)
RuntimeResourceDictionaryValues-237.6k ± 0%37.6k ± 0%−0.02%(p=0.001 n=7+7)
Transfer-21.00 ± 0%1.00 ± 0%~(all equal)
 

@turbolent turbolent force-pushed the bastian/improve-constant-sized-type-parsing branch from 4aa03b8 to 8cfc45e Compare April 29, 2022 17:51
@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #1613 (882dea6) into master (f615bea) will increase coverage by 0.04%.
The diff coverage is 85.00%.

@@            Coverage Diff             @@
##           master    #1613      +/-   ##
==========================================
+ Coverage   74.73%   74.77%   +0.04%     
==========================================
  Files         288      288              
  Lines       55340    55407      +67     
==========================================
+ Hits        41357    41433      +76     
+ Misses      12489    12481       -8     
+ Partials     1494     1493       -1     
Flag Coverage Δ
unittests 74.77% <85.00%> (+0.04%) ⬆️

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

Impacted Files Coverage Δ
runtime/parser2/type.go 88.73% <78.57%> (+0.58%) ⬆️
runtime/parser2/lexer/tokentype.go 98.37% <100.00%> (+0.08%) ⬆️
runtime/sema/checker.go 90.37% <0.00%> (-0.12%) ⬇️
runtime/parser2/expression.go 92.80% <0.00%> (-0.01%) ⬇️
runtime/interpreter/value.go 63.66% <0.00%> (+0.03%) ⬆️
runtime/interpreter/interpreter_expression.go 84.70% <0.00%> (+0.08%) ⬆️
runtime/parser2/parser.go 90.33% <0.00%> (+0.08%) ⬆️
runtime/runtime.go 86.98% <0.00%> (+0.10%) ⬆️
runtime/interpreter/interpreter.go 88.88% <0.00%> (+0.17%) ⬆️
... and 2 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 f615bea...882dea6. 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.

Thanks for adding the negative literal test. I initially did wonder what would happen for the negative literals, but realized it would still be handled, because the next token is the not the 'literal'. Always nice to have a test case 👌

@turbolent turbolent merged commit 378f44e into master May 12, 2022
@turbolent turbolent deleted the bastian/improve-constant-sized-type-parsing branch May 12, 2022 20:26
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.

4 participants