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

7591 abi encoding optimization #7617

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ssonthal
Copy link
Contributor

Fixes Closes Resolves #7591

Please choose one of the keywords above to refer to the issue this PR solves followed by the issue number (e.g. Fixes #000). If no issue number, remove the line. Also, remove everything marked optional that is not applicable. Remove this note after reading.

Changes

  • List the changes

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • [] Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Documentation

Requires documentation update

  • Yes
  • No

If yes, link the PR to the docs update or the issue with the details labeled docs. Remove if not applicable.

Requires explanation in Release Notes

  • Yes
  • No

@ssonthal
Copy link
Contributor Author

ssonthal commented Oct 16, 2024

Hi @LukaszRozmej,

The understanding so far - NettyRlpStream uses ReadOnlySpan and dynamic memory allocation of IByteBuffer to efficiently allocate memory. So we either we can reuse that class in ABI encoding, or create a different class. I went with the second approach and created a rather duplicate called NettyAbiStream with same methods with slight differences (it doesn't inherit RlpStream so we can trim off some methods).

List of changes ->

  1. Created NettyAbiStream that implements IDisposable interface (same as NettyRlpStream).
  2. To confirm if the changes are in the right direction, for one of the AbiType -> AbiAddress, have tried using NettyAbiStream instead of previous byte[] allocation.

Please let me know your thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore this file. Will undo these changes once I have some confirmations from your end.

@ssonthal
Copy link
Contributor Author

Hey @LukaszRozmej , awaiting your feedback on this.

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hard to say without example usages, the one for address doesn't do much

Comment on lines +34 to +42
if (packed)
{
nettyAbiStream.Write(input.Bytes.ToList());
}
else
{
nettyAbiStream.Write(input.Bytes.PadLeft(UInt256.LengthInBytes).ToList());
}
return nettyAbiStream.AsSpan().ToArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you allocate both list and array, not achieving goal of removing allocations

@ssonthal
Copy link
Contributor Author

I understand. Let me go over this again and get back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize ABI API to have less allocation
2 participants