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

Expand interpreter tracing for composite, array and dictionary types #1450

Merged
merged 12 commits into from
Mar 1, 2022

Conversation

ramtinms
Copy link
Contributor

@ramtinms ramtinms commented Feb 25, 2022

Description

This PR expands tracing functionality inside cadence for composite, array and dictionary types. these open traces are disabled by default and upon enabling it, they would be passed to the interface's recordTrace method for further aggregation. These traces are great tools for analyzing the performance of the interpreter when handling these types.


  • 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 Feb 25, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 3705ef1
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
InterpretRecursionFib-22.89ms ± 4%3.24ms ± 6%+12.17%(p=0.001 n=7+7)
ParseFungibleToken-2235µs ± 3%249µs ± 5%+6.29%(p=0.005 n=6+7)
RuntimeResourceDictionaryValues-216.9ms ± 6%17.5ms ± 3%~(p=0.051 n=7+6)
RuntimeFungibleTokenTransfer-21.34ms ±33%1.46ms ±26%~(p=0.165 n=7+7)
ParseInfix-210.3µs ± 7%10.1µs ± 2%~(p=0.445 n=7+6)
ParseArray-215.5ms ± 2%15.4ms ± 2%~(p=0.589 n=6+6)
ParseDeploy/byte_array-223.9ms ± 2%23.5ms ± 4%~(p=0.101 n=7+6)
ParseDeploy/decode_hex-21.47ms ± 1%1.45ms ± 2%~(p=0.065 n=6+6)
QualifiedIdentifierCreation/One_level-23.42ns ± 2%3.45ns ± 4%~(p=0.598 n=7+7)
QualifiedIdentifierCreation/Three_levels-2181ns ± 5%181ns ± 6%~(p=1.000 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2176µs ± 3%178µs ± 3%~(p=0.628 n=7+6)
ContractInterfaceFungibleToken-250.2µs ± 5%51.1µs ± 9%~(p=0.535 n=7+7)
NewInterpreter/new_interpreter-21.35µs ±10%1.35µs ± 3%~(p=0.318 n=7+7)
NewInterpreter/new_sub-interpreter-22.62µs ± 7%2.61µs ± 5%~(p=0.535 n=7+7)
 
alloc/opdelta
InterpretRecursionFib-21.24MB ± 0%1.26MB ± 0%+1.57%(p=0.001 n=7+6)
RuntimeFungibleTokenTransfer-2272kB ± 0%272kB ± 0%~(p=0.128 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-266.2kB ± 0%66.2kB ± 0%~(all equal)
ContractInterfaceFungibleToken-226.6kB ± 0%26.6kB ± 0%~(p=0.385 n=7+6)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.24kB ± 0%1.24kB ± 0%~(all equal)
RuntimeResourceDictionaryValues-24.05MB ± 0%4.05MB ± 0%−0.01%(p=0.012 n=6+7)
 
allocs/opdelta
InterpretRecursionFib-225.0k ± 0%26.2k ± 0%+4.88%(p=0.001 n=7+7)
RuntimeFungibleTokenTransfer-24.52k ± 0%4.52k ± 0%~(p=0.592 n=7+7)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
ContractInterfaceFungibleToken-2458 ± 0%458 ± 0%~(all equal)
NewInterpreter/new_interpreter-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-238.0 ± 0%38.0 ± 0%~(all equal)
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%−0.00%(p=0.009 n=7+7)
 

@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2022

Codecov Report

Merging #1450 (a0d9475) into master (3705ef1) will increase coverage by 0.48%.
The diff coverage is 84.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1450      +/-   ##
==========================================
+ Coverage   72.54%   73.02%   +0.48%     
==========================================
  Files         288      288              
  Lines       39456    39719     +263     
==========================================
+ Hits        28624    29006     +382     
+ Misses       9376     9245     -131     
- Partials     1456     1468      +12     
Flag Coverage Δ
unittests 73.02% <84.55%> (+0.48%) ⬆️

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

Impacted Files Coverage Δ
runtime/interpreter/value.go 58.25% <83.68%> (+1.90%) ⬆️
runtime/interpreter/interpreter_tracing.go 91.66% <87.50%> (+91.66%) ⬆️
runtime/interpreter/interpreter_expression.go 83.11% <100.00%> (+1.04%) ⬆️
runtime/interpreter/interpreter_import.go 100.00% <100.00%> (+18.51%) ⬆️
runtime/sema/simple_type.go 92.85% <0.00%> (-3.58%) ⬇️
runtime/sema/type.go 88.50% <0.00%> (+0.07%) ⬆️
runtime/sema/checker.go 89.24% <0.00%> (+0.17%) ⬆️
runtime/ast/type.go 93.28% <0.00%> (+2.12%) ⬆️
... and 5 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 3705ef1...a0d9475. Read the comment docs.

@ramtinms ramtinms changed the title [WIP] expand interpreter tracing Expand interpreter tracing for composite, array and dictionary types Feb 25, 2022
@ramtinms ramtinms marked this pull request as ready for review February 25, 2022 23:06
@turbolent
Copy link
Member

Just realized: Tracing is disabled by default, so tests will not exercise any of this code.

Could you please add this after https://github.com/onflow/cadence/blob/master/runtime/tests/interpreter/interpreter_test.go#L97-L97:

			interpreter.WithOnRecordTraceHandler(
				func(
					_ *interpreter.Interpreter,
					_ string,
					_ time.Duration,
					_ []opentracing.LogRecord,
				) {
					// NO-OP
				},
			),
			interpreter.WithTracingEnabled(true),

@turbolent
Copy link
Member

Please follow and fill out the checklist, thank you

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.

Looks good!

"github.com/onflow/cadence/runtime/tests/utils"
)

func setupInterpreterWithTracingCallBack(
Copy link
Member

Choose a reason for hiding this comment

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

👌

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.

Looks good, nice work!

Seems like some tests fail.

Should we also port this to 0.23? (the next Cadence release)

@turbolent
Copy link
Member

@ramtinms I looked at the failing tests. Transfer functions are bit tricky, OK if I fix the tracing calls?
Basically, the tracing is using a defer, and by the time the trace is reported, the value has already changed

@ramtinms
Copy link
Contributor Author

ramtinms commented Mar 1, 2022

its not a must-have for 0.23, but would make our life easier if its backported.

@turbolent
Copy link
Member

@ramtinms In f9d8c81 I:

  • Removed the tracing from Clone calls. This is an internal function which is never called by the interpreter, it is only used by e.g. a state migration
  • Unified how the tracing information is prepared
  • Moved the preparation of the tracing information before the deferal (when possible), so it does not access potentially invalidated information/state (e.g. Transfer sets ArrayValue/DictionaryValue/CompositeValue's array/dictionary nil if it is a resource

@ramtinms
Copy link
Contributor Author

ramtinms commented Mar 1, 2022

changes looks great, thanks for taking care of it

@turbolent
Copy link
Member

@SupunS Could you please have a second look?

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 to me!

@turbolent turbolent merged commit e5b31e1 into master Mar 1, 2022
@turbolent turbolent deleted the ramtin/expand-interpreter-tracing branch March 1, 2022 21:38
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