-
Notifications
You must be signed in to change notification settings - Fork 428
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
Reduce Wasm code bloat of emitting ink! events #990
Comments
As an experiment I crudely removed the topics codegen, which reduced |
Maybe we should take into account #809 during implementation of this issue=) |
A promising experiment: I managed to get
|
Did this just work out of the box or were codegen and ink! IR adjustments needed? |
No, I needed to remove the |
This is unfortunately wrong. The correct number is There is however some potential for optimizing the footprint of topics codegen, which requires further investigation. For example, each new type of topic adds |
Currently emitting ink! events is very costly with respect to Wasm file sizes.
The Wasm file size bloat primarily stems from the fact that upon emitting an event we first create an event instances that we immediately encode.
The creation process under Wasm is very costly if an event instance has a large memory footprint.
In the ERC-20 example contract we have several events with a structure like:
Where
AccountId
is 256 bit andBalance
is 128 bit wide. This means that even in packed form theTransferred
struct has a memory footprint of at least 642 bits. Creating instances of this type in Wasm is extremely costly since Wasm has to use the shadow stack for big types like these. What we should do instead is to use references where possible, however:Is currently not an allowed event definition since we require ink! events to be
scale::Encode
andscale::Decode
where the latter requiresSelf: 'static
which is not true for the event definition with references.Maybe we could drop the latter trait bound since we do not really require events to be decodable - that's just a nice-to-have feature.
Note though that the reference-based event definition still has a memory footprint of at least 98 bits which still requires Wasm to use the shadow stack.
OR we may be able to emit event without constructing an event instance in the first place by creating intelligent constructors that work with
EncodeLike<T>
for each event field instead ofT
so it is possible to feed references instead.This potential solution would probably yield the best results since we won't be required to create short-lived instances of potentially big types.
The text was updated successfully, but these errors were encountered: