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

Use Buffer.compare() #5955

Open
twoeths opened this issue Sep 13, 2023 · 0 comments
Open

Use Buffer.compare() #5955

twoeths opened this issue Sep 13, 2023 · 0 comments
Labels
good first issue Issues that are suitable for first-time contributors. help wanted The author indicates that additional help is wanted. meta-feature-request Issues to track feature requests. prio-medium Resolve this some time soon (tm). scope-performance Performance issue and ideas to improve performance.

Comments

@twoeths
Copy link
Contributor

twoeths commented Sep 13, 2023

Problem description

Buffer.compare() is faster than byteArrayEquals() so we should use it

Solution description

  • With 32 bytes array, it's >2x faster
root equals
    ✔ ssz.Root.equals                                                  2.911293e+7 ops/s    34.34900 ns/op        -     291059 runs   10.1 s
    ✔ byteArrayEquals                                                  2.753759e+7 ops/s    36.31400 ns/op        -     275399 runs   10.1 s
    ✔ Buffer.compare                                                   6.513809e+7 ops/s    15.35200 ns/op        -     648881 runs   10.1 s
  • With 100_000_000 bytes array (the size of a mainnet state as of Sep 2023) it's ~22x faster
✔ byteArrayEquals 100_000_000                                         7.908042 ops/s    126.4535 ms/op        -         76 runs   10.2 s
✔ Buffer.compare 100_000_000                                          171.9610 ops/s    5.815271 ms/op        -         10 runs   64.0 s

Additional context

May want to find the same usage in other places like ssz

@twoeths twoeths added the meta-feature-request Issues to track feature requests. label Sep 13, 2023
@philknows philknows added prio-medium Resolve this some time soon (tm). good first issue Issues that are suitable for first-time contributors. help wanted The author indicates that additional help is wanted. scope-performance Performance issue and ideas to improve performance. labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. help wanted The author indicates that additional help is wanted. meta-feature-request Issues to track feature requests. prio-medium Resolve this some time soon (tm). scope-performance Performance issue and ideas to improve performance.
Projects
None yet
Development

No branches or pull requests

2 participants