EOP is a brand-new Motoko feature that has now been released for beta testing in the latest dfx 0.24.1-beta.0
.
Motivation
EOP has been designed with the intention to relieve programmers from dealing with stable memory by offering an upgrade mechanism that is simple, safe, and scalable at the same time:
- Simplicity: By way of orthogonal persistence (the
stable
variables in Motoko), transitively reachable structures of any first-order type are automatically persisted across upgrades. No stable memory or stable data structures are needed. - Safety: The runtime system rigorously checks type compatibility on upgrades and supports several kinds of data changes by implicit migration. Any more complex migration can be implemented by custom code. This prevents any data corruption or misinterpretation at the memory level.
- Scalability: Upgrades become super-fast because the main memory is simply retained on an upgrade. No copying to and from stable memory is needed. The main memory has been extended to 64-bit to scale as large as stable memory in the future.
While orthogonal persistence (stable variables) was already available in previous Motoko versions, EOP significantly strengthens safety and scalability to make it the persistence model of choice. EOP is a feature that is unique to Motoko, as the language and runtime system have been specifically tailored to the properties of the IC.
Configuration
To activate enhanced orthogonal persistence under dfx
(version dfx 0.24.1-beta.0
or higher), the following command-line argument needs to be specified in dfx.json
:
{
"main": "your-program.mo",
"type" : "motoko",
"args" : "--enhanced-orthogonal-persistence",
}
Temporary Limitations
EOP is rolled out in a risk-averse manner, and therefore first comes with limitations that will be relaxed in future:
- Local testing: As of now, EOP does not yet run on the IC mainnet because 64-bit main memory is not yet enabled there. However, EOP can already be tested locally in
dfx
. IC support for Wasm Memory64 and thus EOP is expected to be soon available. - Limited memory: The IC will initially only offer a limited capacity of the 64-bit main memory, e.g. 4GB or 6GB. This will be gradually increased in the future to approach the same capacity as stable memory.
Other Implications
There are several other changes in behavior and runtime properties implied by the EOP that are worth to consider:
-
Upgrades become extremely fast, only depending on the number of types, not on the number of heap objects.
-
Upgrades will no longer hit the IC instruction limit, even for maximum heap usage.
-
Motoko automatically migrates from old 32-bit classical persistence to EOP. However, please note that the reverse direction, downgrading from EOP to 32-bit classical persistence, is not supported.
-
The change to 64-bit increases the memory demand on the heap, in the worst case by a factor of two. This means, while the main memory is still very limited in the initial beta testing phase, there will not be a gain in memory capacity. However, in the long term, 64-bit allows Motoko canisters to scale very large, without needing to change or upgrade the canister.
-
You should expect a moderate regression in terms of instruction costs of around 15% for normal execution due to combined related features, a new IC instruction cost model for Memory64, precise object tagging, change to incremental GC, and handling of compile-time-known data.
-
The garbage collector is fixed to the Incremental GC. This is because this GC is designed for scalability which is what we want to achieve with EOP.
-
Floating point formatting may slightly change: The debug print format of “not a number” is now NaN (originally nan or -nan). Float.format(#hex prec, x) is no longer supported which is probably not frequently used in practice.
-
With the introduction of 64-bit main memory, the charging of cycles per instruction may also be somewhat increased as a conservative operational measure during the testing phase and probably, also during the later production roll out - the rationale behind this will follow in the announcement when Memory64 support is enabled on the IC mainnet.
More Information
For more information, please see:
- Motokos’s enhanced orthogonal persistence: https://internetcomputer.org/docs/current/motoko/main/canister-maintenance/orthogonal-persistence/enhanced
- Stable variables, upgrades, and data migration in Motoko:
https://internetcomputer.org/docs/current/motoko/main/canister-maintenance/upgrades
Contact
If you encounter any issues or have any questions, please do not hesitate to contact us, here in the forum or on the Motoko GitHub repo. We are grateful if you can try it out and are happy to hear your feedback. Please keep in mind that it is still beta testing - so, please do not yet use it for productive cases once the IC mainnet support for EOP is available.