-
Notifications
You must be signed in to change notification settings - Fork 140
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
Allow embedders to reuse interpreter shared state #2100
Allow embedders to reuse interpreter shared state #2100
Conversation
Very nice Does this support rollback on state? Can I use this with debugger to rollback state for example? Like time machine. Is this state is serializable? |
runtime/runtime_test.go
Outdated
func (i *testRuntimeInterface) SetInterpreterSharedState(state *interpreter.SharedState) { | ||
if i.setInterpreterSharedState == nil { | ||
return | ||
} | ||
|
||
i.setInterpreterSharedState(state) | ||
} | ||
|
||
func (i *testRuntimeInterface) GetInterpreterSharedState() *interpreter.SharedState { | ||
if i.getInterpreterShareState == nil { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe panic here like the other testRuntimeInterface methods, since returning nil doesn't signify whether the operation failed or if the interface just doesn't have a fn pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetInterpreterSharedState
is an optional function, the embedder does not need to implement it. The runtime still works if this function is not implemented
The word "state" here refers to the in-memory data structures that the interpreter builds up for executing programs. For example, there is one This interpreter state is unrelated to the "chain execution state", which is called "storage" in Cadence. The interpreter state is not currently serializable. |
Codecov Report
@@ Coverage Diff @@
## master #2100 +/- ##
==========================================
- Coverage 77.71% 77.71% -0.01%
==========================================
Files 304 304
Lines 63529 63563 +34
==========================================
+ Hits 49373 49398 +25
- Misses 12401 12407 +6
- Partials 1755 1758 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:master commit 77938db Collapsed results for better readability
|
cc: @pattyshack |
Closes #2048
Description
Based on @janezpodhostnik's idea and proof-of-concept:
Allow the embedder, e.g. FVM, to reuse the shared state across multiple runtime top-level entry calls (e.g. transaction invocation, contract function invocation).
If the embedder, through the new interface functions
SetInterpreterSharedState
andGetInterpreterSharedState
, saves the state and re-supplies it in a subsequent top-level entry call, interpreters for imported contracts are re-used – contract data does not need to be re-read from storage, and contract values do not need to be recreated by the interpreter.When enabling this optimization for
BenchmarkRuntimeFungibleTokenTransfer
, this optimization improves performance and allocations by ca ~16%:master
branchFiles changed
in the Github PR explorer