https://github.com/hackbg/cw-storage-benchmarks
Gas benchmarks for implementations of storage structures in CosmWasm.
https://github.com/hackbg/cw-storage-benchmarks
Last synced: 11 months ago
JSON representation
Gas benchmarks for implementations of storage structures in CosmWasm.
- Host: GitHub
- URL: https://github.com/hackbg/cw-storage-benchmarks
- Owner: hackbg
- Created: 2023-06-15T11:59:49.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-05T16:58:22.000Z (almost 3 years ago)
- Last Synced: 2025-06-22T07:35:28.730Z (12 months ago)
- Language: Rust
- Size: 57.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CosmWasm storage structures gas cost benches
Persistence is an important aspect of smart contracts.
In CosmWasm, smart contract developers have access to
a fundamental storage primitive: the key-value store.
In the case of Secret Network, libraries like Fadroma
and secret-toolkit build upon the CosmWasm KV store to
implement additional storage structures.
`secret-toolkit` predominantly uses binary blob pages,
where each page contains multiple items in the form of JSON bytes.
Presumably, this done to reduce the number of FFI calls
required to fetch data from the CosmWasm storage runtime.
However, this dramatically increases the complexity of the
implementation of those storage structures.
In contrast, Fadroma uses data mappings where each operation
(insert or get) for each item is a call (or more, depending
on the data structure) to storage.
The purpose of this repo is to measure the gas efficiency of
these distinct approaches with the purpose to hopefully derive
novel and better approaches to more efficiently implement such
storage structures.
The approach would of course greatly depend on the functionality
desired by the structure.
## Map
Just like a regular map, the implementations allow
inserting and getting values from the map, based on a given key.
They also allow for iterating over all the values inserted.
It should be noted that the secret-toolkit version also allows for
iterating over the keys (as opposed to values), whereas Fadroma doesn't.
The benchmark here is the contract accepts N number of items which it then
inserts one by one into the map, then uses the map iterator to iterate over
the values inserted, collecting them into a Vec to include in the response
(just so that we have something to do with those values). Finally, it removes
all the values previously inserted from the map.
The result is, even when bypassing Fadroma's binary serialization by using JSON,
it is still slightly more efficient.
|N items|secret-toolkit (baseline)|Fadroma (w/ JSON serialization)|Fadroma (w/ binary serialization)|
|-------|--------------|------------------------------------------|---------------------------------|
|10 |51318 |50071 (2.43% cheaper) |47472 (7.49% cheaper) |
|20 |65834 |63556 (3.46% cheaper) |58479 (11.17% cheaper) |
|50 |109160 |103702 (5.00% cheaper) |91792 (15.91% cheaper) |
|100 |182156 |170392 (6.46% cheaper) |147534 (19.01% cheaper) |
|200 |325335 |303299 (6.77% cheaper) |256324 (21.21% cheaper) |
|500 |759707 |703917 (7.34% cheaper) |586556 (22.79% cheaper) |
|1000 |1482880 |1369681 (7.63% cheaper) |1138502 (23.22% cheaper) |