Skip to content

Conversation

@SupunS
Copy link
Member

@SupunS SupunS commented Nov 6, 2025

Work towards #3691

Depends on #4335

⚠️ DO NOT MERGE

Description

  • Use the generated static-type based subtyping check for the IsSubType() function (instead of the subtyping check based on sema-type)
  • Remove usages of MustConvertStaticToSemaType in VM, and rely on static-types.
  • Migrate some stdlib functions (e.g: Account related stdlib functions) to only use static-types (replace the usages of sema-type).

Results:

Vs VM in last released version (v1.8.3)

goos: darwin
goarch: arm64
pkg: github.com/onflow/cadence/runtime
cpu: Apple M1 Pro
                                 │ v1.8.3.txt  │             after.txt              │
                                 │   sec/op    │   sec/op     vs base               │
RuntimeFungibleTokenTransferVM-8   291.3µ ± 9%   273.0µ ± 4%  -6.27% (p=0.002 n=10)

                                 │  v1.8.3.txt  │              after.txt              │
                                 │     B/op     │     B/op      vs base               │
RuntimeFungibleTokenTransferVM-8   171.9Ki ± 0%   160.0Ki ± 0%  -6.92% (p=0.000 n=10)

                                 │ v1.8.3.txt  │              after.txt              │
                                 │  allocs/op  │  allocs/op   vs base                │
RuntimeFungibleTokenTransferVM-8   3.082k ± 0%   2.753k ± 0%  -10.67% (p=0.000 n=10)

Vs VM before switching to static-types (master)

goos: darwin
goarch: arm64
pkg: github.com/onflow/cadence/runtime
cpu: Apple M1 Pro
                                 │ before.txt  │             after.txt              │
                                 │   sec/op    │   sec/op     vs base               │
RuntimeFungibleTokenTransferVM-8   285.6µ ± 9%   273.0µ ± 4%  -4.40% (p=0.011 n=10)

                                 │  before.txt  │              after.txt              │
                                 │     B/op     │     B/op      vs base               │
RuntimeFungibleTokenTransferVM-8   170.6Ki ± 0%   160.0Ki ± 0%  -6.21% (p=0.000 n=10)

                                 │ before.txt  │             after.txt              │
                                 │  allocs/op  │  allocs/op   vs base               │
RuntimeFungibleTokenTransferVM-8   3.000k ± 0%   2.753k ± 0%  -8.23% (p=0.000 n=10)

**Note: The master branch also contains some optimizations that was ported over. So the above comparison only includes the improvement we get from switching to static-types only.

Vs Interpreter (master)

goos: darwin
goarch: arm64
pkg: github.com/onflow/cadence/runtime
cpu: Apple M1 Pro
                               │ interpreter.txt │           after.txt           │
                               │     sec/op      │   sec/op     vs base          │
RuntimeFungibleTokenTransfer-8       272.8µ ± 2%   273.0µ ± 4%  ~ (p=0.796 n=10)

                               │ interpreter.txt │              after.txt              │
                               │      B/op       │     B/op      vs base               │
RuntimeFungibleTokenTransfer-8      157.3Ki ± 0%   160.0Ki ± 0%  +1.70% (p=0.000 n=10)

                               │ interpreter.txt │             after.txt              │
                               │    allocs/op    │  allocs/op   vs base               │
RuntimeFungibleTokenTransfer-8       2.980k ± 0%   2.753k ± 0%  -7.62% (p=0.000 n=10)

Next steps

  • There are more stdlib functions that still needs to be updated to use only static-types.
  • Event emitting still need the sema types (hence the conversion exist). Should try to replace those as well.
  • Generated subtype check for static-types still converts to sema types in certain cases (for e.g: conformance information is not available in static-types, so need to convert to sema-type to get these information)

  • 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

@SupunS SupunS self-assigned this Nov 6, 2025
Comment on lines 87 to 89
superTypeAccess := MustConvertStaticAuthorizationToSemaAccess(typeConverter, superTypeAuth)
subTypeAccess := MustConvertStaticAuthorizationToSemaAccess(typeConverter, subTypeAuth)
return sema.PermitsAccess(superTypeAccess, subTypeAccess)
Copy link
Member Author

Choose a reason for hiding this comment

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

This conversion is very expensive. We should try to address this next.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Benchstat comparison

  • Base branch: onflow:feature/subtype-gen
  • Base commit: 19aeaaa
Results

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileTime-433.3µs ± 0%32.6µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4405µs ± 0%413µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-4191µs ± 0%190µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
Emit-44.07ms ± 0%5.16ms ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4257ns ± 0%257ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-479.7ns ± 0%77.9ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-4120µs ± 0%110µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-421.0µs ± 0%26.3µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-413.5µs ± 0%11.6µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewCompilerNewVM-434.1µs ± 0%32.3µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewVM-416.3µs ± 0%13.2µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-42.18ms ± 0%2.46ms ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-4112µs ± 0%139µs ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-421.5µs ± 0%27.4µs ± 0%~(p=1.000 n=1+1)
InterpreterNewStruct-462.3µs ± 0%70.0µs ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-429.5µs ± 0%27.2µs ± 0%~(p=1.000 n=1+1)
MethodCall/interface_method_call-450.9µs ± 0%49.5µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-41.10µs ± 0%1.02µs ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-4314ns ± 0%314ns ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-490.7µs ± 0%82.4µs ± 0%~(p=1.000 n=1+1)
NewStruct-433.8µs ± 0%32.4µs ± 0%~(p=1.000 n=1+1)
NewStructRaw-43.79µs ± 0%3.70µs ± 0%~(p=1.000 n=1+1)
RecursionFib-4826µs ± 0%659µs ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransfer-4730µs ± 0%785µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4593µs ± 0%651µs ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4632µs ± 0%592µs ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-42.60ms ± 0%2.66ms ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-412.0ms ± 0%12.0ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-415.3µs ± 0%15.4µs ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-427.2µs ± 0%23.9µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-470.2ns ± 0%71.3ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileTime-416.3kB ± 0%16.3kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4153kB ± 0%155kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-473.5kB ± 0%73.2kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
Emit-41.48MB ± 0%1.54MB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4120B ± 0%120B ± 0%~(all equal)
ExportType/simple_type-40.00B 0.00B ~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-438.4kB ± 0%33.5kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-48.30kB ± 0%8.30kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-41.94kB ± 0%1.94kB ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-421.8kB ± 0%21.4kB ± 0%~(p=1.000 n=1+1)
ImperativeFibNewVM-44.70kB ± 0%4.36kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-41.19MB ± 0%1.19MB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-439.9kB ± 0%48.2kB ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-48.29kB ± 0%8.29kB ± 0%~(all equal)
InterpreterNewStruct-424.4kB ± 0%26.1kB ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-47.01kB ± 0%6.98kB ± 0%~(p=1.000 n=1+1)
MethodCall/interface_method_call-414.5kB ± 0%14.5kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-4976B ± 0%976B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-4232B ± 0%232B ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-440.3kB ± 0%40.0kB ± 0%~(p=1.000 n=1+1)
NewStruct-410.4kB ± 0%10.4kB ± 0%~(p=1.000 n=1+1)
NewStructRaw-42.60kB ± 0%2.59kB ± 0%~(p=1.000 n=1+1)
RecursionFib-488.1kB ± 0%88.1kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransfer-4238kB ± 0%259kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4159kB ± 0%178kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4173kB ± 0%163kB ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-41.76MB ± 0%1.76MB ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-49.27MB ± 0%9.27MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-48.04kB ± 0%8.04kB ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-49.80kB ± 0%9.80kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-448.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileTime-4176 ± 0%176 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-42.46k ± 0%2.53k ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-4931 ± 0%929 ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
Emit-439.0k ± 0%41.0k ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-43.00 ± 0%3.00 ± 0%~(all equal)
ExportType/simple_type-40.00 0.00 ~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-4968 ± 0%825 ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-4176 ± 0%176 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-449.0 ± 0%49.0 ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-4205 ± 0%203 ± 0%~(p=1.000 n=1+1)
ImperativeFibNewVM-486.0 ± 0%84.0 ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-417.7k ± 0%17.7k ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-4833 ± 0%1003 ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-4175 ± 0%175 ± 0%~(all equal)
InterpreterNewStruct-4418 ± 0%448 ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-4135 ± 0%135 ± 0%~(all equal)
MethodCall/interface_method_call-4285 ± 0%285 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-415.0 ± 0%15.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-44.00 ± 0%4.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-4722 ± 0%720 ± 0%~(p=1.000 n=1+1)
NewStruct-4219 ± 0%219 ± 0%~(all equal)
NewStructRaw-438.0 ± 0%38.0 ± 0%~(all equal)
RecursionFib-43.65k ± 0%3.65k ± 0%~(all equal)
RuntimeFungibleTokenTransfer-43.98k ± 0%4.47k ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-42.98k ± 0%3.41k ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-43.00k ± 0%2.75k ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-436.7k ± 0%36.7k ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-4159k ± 0%159k ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-4113 ± 0%113 ± 0%~(all equal)
RuntimeVMInvokeContractImperativeFib-4197 ± 0%197 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-41.00 ± 0%1.00 ± 0%~(all equal)
 

@SupunS SupunS force-pushed the supun/subtype-gen-runtime branch from 493119f to 37527c7 Compare November 6, 2025 23:14
@SupunS SupunS changed the base branch from feature/subtype-gen to supun/subtype-gen-statictypes November 10, 2025 19:33
@SupunS SupunS changed the base branch from supun/subtype-gen-statictypes to supun/subtype-gen-statictypes-tests November 13, 2025 22:03
Base automatically changed from supun/subtype-gen-statictypes-tests to feature/subtype-gen November 14, 2025 20:43
@SupunS SupunS force-pushed the supun/subtype-gen-runtime branch from 0107539 to ac573c0 Compare November 14, 2025 23:06
@SupunS SupunS marked this pull request as ready for review November 14, 2025 23:14
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.

2 participants