Skip to content

Commit 696b79c

Browse files
committed
Delivery report for OpenBrush follow-up milestone 1
1 parent 3b6be59 commit 696b79c

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Milestone Delivery :mailbox:
2+
3+
**The [invoice form :pencil:](https://docs.google.com/forms/d/e/1FAIpQLSfmNYaoCgrxyhzgoKQ0ynQvnNRoTmgApz9NrMp-hd8mhIiO0A/viewform) has been filled out correctly for this milestone and the delivery is according to the official [milestone delivery guidelines](https://github.com/w3f/Grants-Program/blob/master/docs/milestone-deliverables-guidelines.md).**
4+
5+
* **Application Document:** [OpenBrush follow-up](https://github.com/w3f/Grants-Program/pull/621).
6+
* **Milestone Number:** 1 milestone of the grant and 3 milestone of the OpenBrush
7+
8+
**Context**
9+
10+
In the scope of that milestone, we investigated what takes most of the code and tried to reduce it or provide a report about potential optimization processes.
11+
12+
A lot of space was taken by the blob from `ink_storage::collections::StorageHashMap`.
13+
So we implemented a lightweight version without caching of elements(`SimpleHashMap`)
14+
and provided a report in [the issue](https://github.com/paritytech/ink/issues/945#issuecomment-930427082) to ink!.
15+
Later the ink! team created their own implementation of `Mapping` by using our example of it.
16+
17+
The dispatching logic of messages and constructors in the ink! generates a lot of code. We found several moments that can be optimized:
18+
19+
- [Replacing `#[inline(always)]` by `#[inline]`](https://github.com/paritytech/ink/pull/1012)
20+
helped to reduce the size of contracts with a lot of messages.
21+
It helped because the compiler decided by self where better to inline to reduce the size of the contract.
22+
[The report about size reduction](https://github.com/paritytech/ink/pull/1012#pullrequestreview-804747290).
23+
- [That change](https://github.com/paritytech/ink/pull/1017) contains many small optimizations
24+
that allow reducing the size of the code well. We can't extract them to
25+
separate PRs because they depend on each other. The main idea is to move common
26+
parts of each message to one place instead of duplicating them. Reworking of
27+
`scale::Decode::decode` logic for arguments also improves the size.
28+
Initially, this change was implemented by [the PR](https://github.com/paritytech/ink/pull/999).
29+
But later we found how it can be optimized more and created a [new PR](https://github.com/paritytech/ink/pull/1017).
30+
Description of the PR contains a report about the size and [this comment](https://github.com/paritytech/ink/pull/1017#issuecomment-970575796).
31+
32+
During the implementation of the [PR](https://github.com/paritytech/ink/pull/1017)
33+
we found out that sub-contracts from the `delegator` example take a lot of space
34+
in comparison to other simple contracts. We investigated that point and found out
35+
the reason in `workspace`. We created [that report](https://github.com/paritytech/ink/pull/1054)
36+
and later created the fix in [`cargo-contract`](https://github.com/paritytech/cargo-contract/pull/378).
37+
38+
During debugging of `#[inline]` methods we figured out that applying of `-Clinker-plugin-lto`
39+
flag during compilation reduces the size of the contract. For small contracts,
40+
it is ~200 bytes, for big ~900 bytes. We heve done [PR](https://github.com/paritytech/cargo-contract/pull/358)
41+
in the `cargo-contract` repository with that fix.
42+
43+
During analyzing of the dispatching WASM blob, we explored that `scale:::Decode`
44+
is not optimally implemented for `AccountId`(and for all arrays like `[u8; N]` structures).
45+
We heve done a [change](https://github.com/paritytech/ink/pull/1016) in ink! repository([report](https://github.com/paritytech/ink/pull/1016#issuecomment-970425793)).
46+
But later we implemented that change in [`parity-scale-codec`](https://github.com/paritytech/parity-scale-codec/pull/299).
47+
It also [improved the performance](https://github.com/paritytech/parity-scale-codec/pull/299#issuecomment-974819024)
48+
during runtime for all WASM-based code(so it also improved some stuff in `substrate`).
49+
50+
**Deliverables**
51+
52+
| Number | Deliverable | Link | Notes |
53+
| ------------- | ------------- | ------------- |------------- |
54+
| 0b. | Documentation | In context section | Each pull request and the issue contains information about size-reduction. |
55+
| 1. | Reduce the size of Erc20 contract | In context section | We did several changes to reduce the size of the contract. A detailed report in the context section. |
56+
57+
**Additional Information**
58+
59+
We did more progress than specified in the grant application.
60+
61+
What was specified:
62+
> We want to briefly(not full change, only minimal changes to reduce the size) implement them and provide a report(re-working data structure, reducing monomorphization, using dynamic dispatch in some cases).
63+
64+
In the description of the milestone, we mentioned that we're going to do "not full change,
65+
only minimal changes to reduce the size", but we implemented them fully and it took more time.
66+
Is it possible to increase payment for that milestone from 9,000 USD to 15,000?

0 commit comments

Comments
 (0)