paritytech / paritytech/revive
Optimization ideas
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Rust
- Stars
- 102
- Forks
- 26
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 6
Description
- We need to cast pointers safely from i256 to register size ints when calling into runtime API methods. While in theory all pointers should be automatically in bounds, this assumption doesn't necessarily hold (as pointers / memory offsets are potentially untrusted user input). Safe truncation adds a lot of overhead in contract code; I tried to offload it into it's own function but on 32bit PolkaVM leads to even more code overall (because we have an i256 argument). On 64bit this could work though and if so we should use this optimization when compiling for size (
-Oz). -
zbbinstructions need to be implemented in PolkaVM. By experimentally switching the LLVM target to rv64 with+zbbsignificant changes in code size can be observed:---- cases::tests::codesize stdout ---- ERC20: 93072 bytes (change from 194140 bytes) Baseline: 63128 bytes (change from 131084 bytes) Flipper: 63688 bytes (change from 131796 bytes) Fibonacci: 63880 bytes (change from 133328 bytes) Computation: 65056 bytes (change from 135456 bytes) - Investigate potential improvements of byte swaps, memset, memmove, mulmod, divs and the like
- Check all alignments, attributes etc. if they still make sense with our target
- Related: https://github.com/paritytech/revive/issues/62
- Pass YUL values as pointers instead of values to a) prevent loading from and spilling to stack back and forth b) use registers more efficiently
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the compiler's PolkaVM target handling and the codesize tests referenced in the issue, including the ERC20, Baseline, Flipper, Fibonacci, and Computation cases. Compare the remaining unchecked areas—byte swaps, memset, memmove, mulmod, divs, and YUL value passing—with the related issue #62. Done is not defined as one change; the selected optimization should have measured code-size or runtime benefits and preserve target correctness.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, solidity
- Domain
- blockchain, compilers, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100