Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to skip storage's lazy behavior and caching #916

Closed
Tracked by #9354
cmichi opened this issue Sep 13, 2021 · 1 comment
Closed
Tracked by #9354

Make it possible to skip storage's lazy behavior and caching #916

cmichi opened this issue Sep 13, 2021 · 1 comment
Labels
A-ink_storage [ink_storage] Work Item B-design Designing a new component, interface or functionality. B-research Research task that has open questions that need to be resolved. C-discussion An issue for discussion for a given topic. P-high High priority issue.

Comments

@cmichi
Copy link
Collaborator

cmichi commented Sep 13, 2021

We need to look into minimizing complexity in ink!. This is needed for paritytech/substrate#9354.

Problem Statement

We found that when compared to Solang-compiled contracts, ink! contracts are about three times larger (ink! ERC-20: 30K, Solang: 9K when manually run through wam-opt). The most likely explanation is that in Solang/Solidity there is no layer between runtime access calls ‒ so no lazy-datastructures and no caching ‒ reads/writes/runtime calls are just executed.
In ink! on the other hand, we have a significant complexity layer to minimize calls into the runtime. This was done with the intention of minimizing gas costs and increase performance.

A major correlation we found though is that smaller code size means better performance. This is due to the fact that runtime calls are not as performance-expensive as we thought, more Wasm bytecode is actually the performance-expensive thing.
Part of the explanation for this is that the contracts pallet injects gas metering into the Wasm bytecode. If there is more Wasm bytecode, more gas metering is injected. This gas metering is a call into the runtime. So by trying to reduce runtime calls through a complexity layer in ink! we introduced more code, which in turn unfortunately results in a gas metering runtime call.

What we should do

We have to modify ink! in a way that it's possible to skip caching and lazy mechanisms. Ideally this would happen by duplicating our ink_storage crate and modify it this way. I'm not sure if we can keep the changes local to that crate though. But if we manage, it would enable developers deciding by themselves which crate to use; this might make sense since it's likely that at least gas costs will be higher when skipping caching and lazy mechanisms.

Open Question

An open question is how gas costs of the contracts will change if we skip our cache/lazy layers. But right now the higher priority is to improve the throughput by reducing contract sizes.

@cmichi cmichi added B-design Designing a new component, interface or functionality. A-ink_storage [ink_storage] Work Item C-discussion An issue for discussion for a given topic. P-high High priority issue. B-research Research task that has open questions that need to be resolved. labels Sep 13, 2021
@cmichi
Copy link
Collaborator Author

cmichi commented Mar 25, 2022

I'm closing this issue, since we now have the Mapping data structure which doesn't have any lazy behavior anymore.

@cmichi cmichi closed this as completed Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_storage [ink_storage] Work Item B-design Designing a new component, interface or functionality. B-research Research task that has open questions that need to be resolved. C-discussion An issue for discussion for a given topic. P-high High priority issue.
Projects
None yet
Development

No branches or pull requests

1 participant