-
Notifications
You must be signed in to change notification settings - Fork 446
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
Optimize ABI API to have less allocation #7591
Comments
Hi @LukaszRozmej can I work on this? I read a bit about streams and spans. Streams are likely to work better when we have large chunk of data of variable sizes while spans work better with structured fixed-size data and the latter offers better performance enhancement, maintains concurrency in a better way. What would you suggest is a better approach? I am currently not aware about the data that Abi encoding deals with. |
Sure, take a look at: https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.Abi/AbiEncoder.cs and everything under it (AbiTypes etc). This now allocates a ton of objects when you Decode and ton of byte arrays when you Encode. Think how can you allocate as little as possible. For inspiration you can check how our Rlp Encoding/Decoding works with NettyRlpStream that is based on pooled memory. |
@LukaszRozmej can we try to optimize this? - In AbiBytes class's Encode method PadRight method is used like this - , The PadRight method create new byte array allocations like this and this method is used at multiple places. |
Hey @LukaszRozmej , gentle nudge for your advise on this. |
We definitely should be able to, but this is just tip of the iceberg and I think there are way more ways to optimise ABI |
Maybe we can break it down to subtasks for incremental progress? |
Hey @LukaszRozmej so for PadLeft and Slice methods, we can start changing the concerned files by using object pools instead of new allocations. Can I take his as the first subtask for this issue? |
I think using object pools might be hard as a lot of those arrays are then later returned upstream, so the upstream would have to track and eventually return them. But if we try changing to |
Got it! So I will try to use Span/Memory instead of creating new byte arrays. |
Encoding and Decoding ABI allocates a lot, rewrite it to a version that will allocate a lot less (stream-like or spans?) and update usages.
The text was updated successfully, but these errors were encountered: