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

Improve dyn-abi encoding performance #75

Closed
DaniPopes opened this issue Jun 7, 2023 · 5 comments
Closed

Improve dyn-abi encoding performance #75

DaniPopes opened this issue Jun 7, 2023 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@DaniPopes
Copy link
Member

DaniPopes commented Jun 7, 2023

Benchmark from #57, as of commit 64bf519:

ethabi/encode/single    time:   [82.202 ns 82.358 ns 82.525 ns]                                 
ethabi/encode/struct    time:   [164.10 ns 165.43 ns 166.85 ns]                                 

ethabi/decode/word      time:   [34.678 ns 34.765 ns 34.861 ns]                                
ethabi/decode/dynamic   time:   [78.638 ns 78.759 ns 78.910 ns]                                  

dyn-abi/encode/single   time:   [68.373 ns 68.550 ns 68.741 ns]                                  
dyn-abi/encode/struct   time:   [683.96 ns 684.70 ns 685.52 ns]                                   

dyn-abi/decode/word     time:   [54.141 ns 54.203 ns 54.266 ns]                                
dyn-abi/decode/dynamic  time:   [80.822 ns 80.932 ns 81.053 ns]                                   

sol-types/encode/single time:   [42.843 ns 43.007 ns 43.207 ns]                                     
sol-types/encode/struct time:   [49.110 ns 49.171 ns 49.235 ns]                                    

sol-types/decode/word   time:   [1.3375 ns 1.3389 ns 1.3405 ns]                                   
sol-types/decode/dynamic                                                                             
                        time:   [39.279 ns 39.478 ns 39.721 ns]

Maybe we can skip tokenizing by encoding directly the DynSolValue? Looking at the "struct" bench, ethabi is much more concise because of ethabi::encode(tokens: &[ethabi::Token]), while dyn-abi has to declare all the types, and then also clone the input on each call.

Originally posted by @DaniPopes in #57 (comment)

@DaniPopes DaniPopes added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jun 7, 2023
@prestwich
Copy link
Member

Maybe we can skip tokenizing by encoding directly the DynSolValue? Looking at the "struct" bench, ethabi is much more concise because of ethabi::encode(tokens: &[ethabi::Token]), while dyn-abi has to declare all the types, and then also clone the input on each call.

this is the official plan now

@moh-eulith
Copy link
Contributor

I implemented this here: https://github.com/moh-eulith/alloy-core/tree/dynperf
but I don't consider it PR worthy for the following reason:
I don't see a good test suite (did I miss it?). The variation in input is near infinite.
a) Is there another task to add tests?
b) Are there tests elsewhere that can be copied over?

@moh-eulith
Copy link
Contributor

Sorry, I just noticed the recent work on this. You might want to play with that branch above. The struct case is noticeably faster.

@prestwich
Copy link
Member

the tests that need to be ported are in sol-type
encoder
decoder

@prestwich
Copy link
Member

closing this as we've made significant improvements and added tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants