dfinity / motoko

Simple high-level language for writing Internet Computer canisters
Apache License 2.0
505 stars 97 forks source link

Record Upgrade Instructions for Classical Persistence #4676

Open luc-blaeser opened 1 month ago

luc-blaeser commented 1 month ago

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

  1. The pre-upgrade records its consumed instructions, in particular for stabilization, in the stable memory metadata. The location depends on the stable memory version.
  2. The post-upgrade loads this information, if present, and adds its consumed instructions, in particular for destabilization.
  3. 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

github-actions[bot] commented 1 month ago

Comparing from 247aa056afe9d5499f9f79d78d6d38117b8478ae to cd60245b38e067b3c68676b5230a928161646f5c: In terms of gas, no changes are observed in 5 tests. In terms of size, 5 tests regressed and the mean change is +0.1%.

luc-blaeser commented 2 weeks ago

Thank you for the review, Claudio!