motoko
motoko copied to clipboard
Record Upgrade Instructions for Classical Persistence
Also support Prim.rts_upgrade_instructions()
on classical persistence, to inspect the instructions consumed by the last upgrade (including stabilization plus destabilization) for performance measurements. This functionality is already supported with enhanced orthogonal persistence.
Mechanism
- The pre-upgrade records its consumed instructions, in particular for stabilization, in the stable memory metadata. The location depends on the stable memory version.
- The post-upgrade loads this information, if present, and adds its consumed instructions, in particular for destabilization.
-
Prim.rts_upgrade_instructions()
returns the sum of those costs.
Backwards Compatibility
The record of upgrade instructions is optional in the stable memory. This is to ensure backwards compatibility to older Motoko programs that do not record this information. When upgrading from such an older Motoko program, Prim.rts_upgrade_instructions()
returns Nat64.maximumValue
.
Notes
-
Prim.rts_upgrade_instructions()
currently returns >0 after installation because some upgrade check needs to be performed there too. - This function is to be exposed to the Motoko base library together with the other diagnostic runtime information, since
Prim
is only intended for internal use.