diff --git a/docs/miscellaneous/memory.md b/docs/miscellaneous/memory.md index 446b3976..43de7eda 100644 --- a/docs/miscellaneous/memory.md +++ b/docs/miscellaneous/memory.md @@ -10,7 +10,7 @@ A [satellite] can store data using two types of memory: `heap` and `stable`. Whi `Heap` memory offers the best performance for accessing data, both for reading and writing. However, it has a limited capacity in terms of the space it can occupy, with a max of 1 GB. -On the other hand, `stable` memory has a higher memory threshold with a maximum limit of 96 GB minus the heap size, allowing it to store more data in terms of size. However, it is slightly slower. +On the other hand, `stable` memory has a higher memory threshold with a maximum limit of 400 GB minus the heap size, allowing it to store more data in terms of size. However, it is slightly slower. Additionally, `heap` memory needs to be deserialized and serialized each time you upgrade the smart contract's code. This process becomes heavier as the heap memory size grows. @@ -20,25 +20,29 @@ On the contrary, `stable` memory doesn't require processing during an upgrade. H There are no strict rules governing the choice of memory type for your use case. Ultimately, the decision lies with you, based on what best suits your project. This is why both the [datastore](../build/datastore.md) and [storage](../build/storage.md) support both memory types. -However, we generally recommend using `heap` for small data or data that require frequent access, and `stable` for large data or data accessed less often. +In practice, `heap` memory can be recommended for small datasets or data that require quick or frequent access, while `stable` memory is preferred for large data or data accessed less often. -This is why the default options for creating new collections are `heap` for datastore and `stable` for storage. +This is why, for example, your dapp's bundle assets (including JS, HTML, images, etc.) are stored within the `heap` memory of satellites. + +However, this decision, along with the memory limitations, results in a significant portion of the `heap` memory being allocated. Although `stable` memory is slightly slower and comes at a higher cost, it is well-suited for storing data and ensuring smooth smart contract upgrades. This is particularly important for the operation and lifecycle of a project. + +That's why the default option for creating new collections is set to `stable` for both datastore and storage. ## Default usage -For the reasons mentioned above, your users, as well as your dapp's bundle and assets (including JS, HTML, images, etc., everything you deploy to your satellite using `juno deploy`), are stored in the `heap` memory. +As mentioned in the previous chapter, your dapp's bundle and assets (everything you deploy to your satellite using `juno deploy`), are stored in the `heap` memory. -In contrast, the [analytics](../build/analytics.md) data is saved within stable memory. +In contrast, your users (as of Satellite version 0.0.16) and the [analytics](../build/analytics.md) data are saved within `stable` memory. ## Summary -| Aspect | Heap Memory | Stable Memory | -| --------------- | ---------------------------------------------------- | --------------------------------------------------- | -| **Capacity** | Max 1 GB | Max 96 GB (minus heap size) | -| **Performance** | Fast for read and write operations | Slightly slower | -| **Cost** | Lower cost | Higher cost (~20x) | -| **Upgrades** | Data must be deserialized/serialized during upgrades | Data are not processed during upgrades | -| **Usage** | Suitable for small or frequently accessed data | Suitable for large or less frequently accessed data | +| Aspect | Heap Memory | Stable Memory | +|--------------------| ---------------------------------------------------- |-----------------------------------------------------| +| **Capacity** | Max 1 GB | Max 400 GB (minus heap size) | +| **Performance** | Fast for read and write operations | Slightly slower | +| **Cost** | Lower cost | Higher cost (~20x) | +| **Upgrades** | Data must be deserialized/serialized during upgrades | Data are not processed during upgrades | +| **Usage** | Suitable for small or frequently accessed data | Suitable for large or less frequently accessed data | ## Resources