update test to match fvm benchmark
DO NOT MERGE - experiment
I was just curious how fvm vs cadence benchmark compares for same (at least close to same) token transfer tx.
I took FVM benchmark @janezpodhostnik added here: https://github.com/onflow/flow-execution-effort-estimation/pull/80 The Tx this runs is:
transaction(){
prepare(signer: auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account) {
var f: fun(): Void = fun(){}
f = fun() {
var i = 0
while i < 26 {
i = i + 1
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)!
let receiverRef = getAccount(signer.address)
.capabilities.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)!
receiverRef.deposit(from: <-vaultRef.withdraw(amount: 0.00001))
}
}
f()
}
execute {
var f: fun(): Void = fun(){}
}
}
Then I updated Cadence testRuntimeFungibleTokenTransfer test to match the transaction above (see the change in this PR).
FVM Benchmark_GlobalRegistry/[TTS_26]-14 230 5,147,458 ns/op
Cadence interpreter BenchmarkRuntimeFungibleTokenTransferInterpreter-14 690 1,618,031 ns/op 1672294 B/op 36598 allocs/op
Cadence VM BenchmarkRuntimeFungibleTokenTransferVM-14 972 1,124,029 ns/op 1160718 B/op 26218 allocs/op
Benchstat comparison
- Base branch: onflow:master
- Base commit: 5ec4685f8c409061b99998697220e0c3492933fc
Results
| old.txt | new.txt | |||
|---|---|---|---|---|
| time/op | delta | |||
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| ContractFunctionInvocation-4 | 402µs ± 0% | 405µs ± 0% | ~ | (p=1.000 n=1+1) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| Emit-4 | 4.11ms ± 0% | 4.00ms ± 0% | ~ | (p=1.000 n=1+1) |
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| ExportType/composite_type-4 | 272ns ± 0% | 266ns ± 0% | ~ | (p=1.000 n=1+1) |
| ExportType/simple_type-4 | 77.6ns ± 0% | 78.0ns ± 0% | ~ | (p=1.000 n=1+1) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| ImperativeFib-4 | 20.4µs ± 0% | 20.5µs ± 0% | ~ | (p=1.000 n=1+1) |
| InterpretRecursionFib-4 | 2.23ms ± 0% | 2.14ms ± 0% | ~ | (p=1.000 n=1+1) |
| NewInterpreter/new_interpreter-4 | 1.05µs ± 0% | 1.03µs ± 0% | ~ | (p=1.000 n=1+1) |
| NewInterpreter/new_sub-interpreter-4 | 315ns ± 0% | 314ns ± 0% | ~ | (p=1.000 n=1+1) |
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| RuntimeFungibleTokenTransferInterpreter-4 | 598µs ± 0% | 5598µs ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeFungibleTokenTransferVM-4 | 638µs ± 0% | 4114µs ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeResourceDictionaryValues-4 | 2.59ms ± 0% | 2.58ms ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeResourceTracking-4 | 12.0ms ± 0% | 12.1ms ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeScriptNoop-4 | 14.8µs ± 0% | 14.1µs ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeVMInvokeContractImperativeFib-4 | 27.7µs ± 0% | 27.5µs ± 0% | ~ | (p=1.000 n=1+1) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| ValueIsSubtypeOfSemaType-4 | 68.8ns ± 0% | 67.3ns ± 0% | ~ | (p=1.000 n=1+1) |
| alloc/op | delta | |||
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| ContractFunctionInvocation-4 | 152kB ± 0% | 152kB ± 0% | ~ | (p=1.000 n=1+1) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| Emit-4 | 1.48MB ± 0% | 1.48MB ± 0% | ~ | (p=1.000 n=1+1) |
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| ExportType/composite_type-4 | 120B ± 0% | 120B ± 0% | ~ | (all equal) |
| ExportType/simple_type-4 | 0.00B | 0.00B | ~ | (all equal) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| ImperativeFib-4 | 8.30kB ± 0% | 8.30kB ± 0% | ~ | (all equal) |
| InterpretRecursionFib-4 | 1.19MB ± 0% | 1.19MB ± 0% | ~ | (p=1.000 n=1+1) |
| NewInterpreter/new_interpreter-4 | 976B ± 0% | 976B ± 0% | ~ | (all equal) |
| NewInterpreter/new_sub-interpreter-4 | 232B ± 0% | 232B ± 0% | ~ | (all equal) |
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| RuntimeFungibleTokenTransferInterpreter-4 | 159kB ± 0% | 1665kB ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeFungibleTokenTransferVM-4 | 173kB ± 0% | 1163kB ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeResourceDictionaryValues-4 | 1.76MB ± 0% | 1.76MB ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeResourceTracking-4 | 9.27MB ± 0% | 9.26MB ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeScriptNoop-4 | 8.03kB ± 0% | 8.04kB ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeVMInvokeContractImperativeFib-4 | 9.80kB ± 0% | 9.80kB ± 0% | ~ | (all equal) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| ValueIsSubtypeOfSemaType-4 | 48.0B ± 0% | 48.0B ± 0% | ~ | (all equal) |
| allocs/op | delta | |||
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| ContractFunctionInvocation-4 | 2.46k ± 0% | 2.46k ± 0% | ~ | (all equal) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| Emit-4 | 39.0k ± 0% | 39.0k ± 0% | ~ | (all equal) |
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| ExportType/composite_type-4 | 3.00 ± 0% | 3.00 ± 0% | ~ | (all equal) |
| ExportType/simple_type-4 | 0.00 | 0.00 | ~ | (all equal) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| ImperativeFib-4 | 176 ± 0% | 176 ± 0% | ~ | (all equal) |
| InterpretRecursionFib-4 | 17.7k ± 0% | 17.7k ± 0% | ~ | (all equal) |
| NewInterpreter/new_interpreter-4 | 15.0 ± 0% | 15.0 ± 0% | ~ | (all equal) |
| NewInterpreter/new_sub-interpreter-4 | 4.00 ± 0% | 4.00 ± 0% | ~ | (all equal) |
| pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64 | ||||
| RuntimeFungibleTokenTransferInterpreter-4 | 2.98k ± 0% | 36.89k ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeFungibleTokenTransferVM-4 | 3.00k ± 0% | 26.62k ± 0% | ~ | (p=1.000 n=1+1) |
| RuntimeResourceDictionaryValues-4 | 36.7k ± 0% | 36.7k ± 0% | ~ | (all equal) |
| RuntimeResourceTracking-4 | 159k ± 0% | 159k ± 0% | ~ | (all equal) |
| RuntimeScriptNoop-4 | 113 ± 0% | 113 ± 0% | ~ | (all equal) |
| RuntimeVMInvokeContractImperativeFib-4 | 197 ± 0% | 197 ± 0% | ~ | (all equal) |
| pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64 | ||||
| ValueIsSubtypeOfSemaType-4 | 1.00 ± 0% | 1.00 ± 0% | ~ | (all equal) |
oh wow, I piggy-back on this updated test to compare the interpreter (master), vm (master), and optimized-vm (https://github.com/onflow/cadence/pull/4322), and the results are:
goos: darwin
goarch: arm64
pkg: github.com/onflow/cadence/runtime
cpu: Apple M1 Pro
│ interpreter_master.txt │ vm_master.txt │ vm_optimized.txt │
│ sec/op │ sec/op vs base │ sec/op vs base │
RuntimeFungibleTokenTransfer-8 2.752m ± 3% 1.906m ± 4% -30.75% (p=0.000 n=10) 1.490m ± 2% -45.86% (p=0.000 n=10)
│ interpreter_master.txt │ vm_master.txt │ vm_optimized.txt │
│ B/op │ B/op vs base │ B/op vs base │
RuntimeFungibleTokenTransfer-8 1639.7Ki ± 0% 1144.0Ki ± 0% -30.23% (p=0.000 n=10) 844.9Ki ± 0% -48.47% (p=0.000 n=10)
│ interpreter_master.txt │ vm_master.txt │ vm_optimized.txt │
│ allocs/op │ allocs/op vs base │ allocs/op vs base │
RuntimeFungibleTokenTransfer-8 36.90k ± 0% 26.63k ± 0% -27.83% (p=0.000 n=10) 20.64k ± 0% -44.07% (p=0.000 n=10)