Skip to content

Commit 55c81dd

Browse files
committed
distinguishing between resource and storage slot
1 parent 27c473a commit 55c81dd

File tree

1 file changed

+11
-11
lines changed
  • apps/nextra/pages/en/build/smart-contracts

1 file changed

+11
-11
lines changed

apps/nextra/pages/en/build/smart-contracts/maps.mdx

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ We will go over their differences and similarities, and how to choose which one
99

1010
## Aptos Blockchain performance and gas cost considerations
1111

12-
Aptos Blockchain state is managed through on-chain **resources**.
13-
Furthermore, transaction performance and gas cost is heavily influenced by how these resources are read and written.
12+
Aptos Blockchain state is kept in **storage slots**.
13+
Furthermore, transaction performance and gas cost is heavily influenced by how these **slots** are read and written.
1414
Breaking down the gas costs further, we have:
15-
1. Storage fee, which are determined by the number and size of resources (i.e., writing to a new resource incurs the highest storage fee, whereas deleting an existing resource provides the largest refund.)
15+
1. Storage fee, which are determined by the number and size of **slots** (i.e., writing to a new **slot** incurs the highest storage fee, whereas deleting an existing **slot** provides the largest refund.)
1616
2. IO gas costs —generally much lower— which depend on the number and size of resources read and modified.
1717
3. execution gas costs are based on the computation needed, and are generally in the similar scale as io gas costs.
1818

19-
Transactions that modify the same resource cannot be executed in parallel, as they conflict with one another.
19+
Transactions that modify the same **slot** cannot be executed in parallel (with some exceptions, like aggregators and resources as a part of the same resource group), as they conflict with one another.
2020

21-
One useful analogy is thinking about each resource being a file on a disk,
21+
One useful analogy is thinking about each **slot** being a file on a disk,
2222
then performance of smart contract would correlate well to a program that
2323
operates on files in the same way.
2424

2525
## Different Map implementations
2626

2727
| Implementation | Size Limit | Storage Structure | Key Features |
2828
|--------------------|------------|------------------|--------------|
29-
| `OrderedMap` | Bounded (fits in a single resource) | Stored entirely within the resource | Supports ordered access (front/back, prev/next), implemented as sorted vector, but operations are effectively O(log(n)) due to internal optimizations |
30-
| `Table` | Unbounded | Each (key, value) stored in a separate resource | Supports basic operations, like `add`, `remove`, `contains`, but **not iteration**, and **cannot be destroyed**; useful for large/unbounded keys/values and high-parallelism cases |
29+
| `OrderedMap` | Bounded (fits in a single **slot**) | Stored entirely within the resource that contains it | Supports ordered access (front/back, prev/next), implemented as sorted vector, but operations are effectively O(log(n)) due to internal optimizations |
30+
| `Table` | Unbounded | Each (key, value) stored in a separate **slot** | Supports basic operations, like `add`, `remove`, `contains`, but **not iteration**, and **cannot be destroyed**; useful for large/unbounded keys/values and high-parallelism cases |
3131
| `TableWithLength` | Unbounded | same as `Table` | Variant of `Table`, with additional length tracking, which adds `length`, `empty`, and `destroy_empty` methods; Adding or removing elements **cannot** be done in parallel, modifying existing elements can. |
32-
| `BigOrderedMap` | Unbounded | Combines multiple keys into a single resource, and grows into multiple resources dynamically | Implemented as B+ tree; **opportunistically parallel** for non-adjacent keys; supports ordered access (front/back, prev/next); configurable node capacities to balance storage and performance |
32+
| `BigOrderedMap` | Unbounded | Combines multiple keys into a single **slot**, initially stored within resource that contains it, and grows into multiple **slots** dynamically | Implemented as B+ tree; **opportunistically parallel** for non-adjacent keys; supports ordered access (front/back, prev/next); configurable node capacities to balance storage and performance |
3333

3434
Note:
3535
- `SimpleMap` has been deprecated, and replaced with `OrderedMap`.
@@ -46,8 +46,8 @@ We measured performance at small scale, measuring microseconds taken for a singl
4646
| 1000 | 105 | 168 | 567 |
4747
| 10000 | 142 | 210 | 656 |
4848

49-
You can see that overhead of `BigOrderedMap` compared to `OrderedMap`, when both are in the single resource, is around 1.5-2x.
50-
So you can generally used `BigOrdredMap` when it is unknown if data will be too large to be stored in a single resource.x
49+
You can see that overhead of `BigOrderedMap` compared to `OrderedMap`, when both are in the single **slot**, is around 1.5-2x.
50+
So you can generally used `BigOrdredMap` when it is unknown if data will be too large to be stored in a single **slot**.
5151

5252
## Common map operations:
5353

@@ -143,7 +143,7 @@ Implementation has few characteristics that make it very versatile and useful ac
143143
- It reduces amount of conflicts: modifications to a different part of the key-space are generally parallel, and it provides knobs for tuning between parallelism and size
144144
- All operations have guaranteed upper-bounds on performance (how long they take, as well as how much execution and io gas they consume), allowing for safe usage across a variety of use cases.
145145
- One caveat, is refundable storage fee. By default, operation that requires map to grow to more resources needs to pay for storage fee for it. Implementation here has an option to pre-pay for storage slots, and to reuse them as elements are added/removed, allowing applications to achieve fully predictable overall gas charges, if needed.
146-
- If key/value is within the size limits map was configured with, inserts will never fail unpredictably, as map internally understands and manages maximal resource size limits.
146+
- If key/value is within the size limits map was configured with, inserts will never fail unpredictably, as map internally understands and manages maximal **slot** size limits.
147147

148148
#### Creating `BigOrderedMap`
149149

0 commit comments

Comments
 (0)