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

ssz.Root.equals performance #2708

Closed
twoeths opened this issue Jun 16, 2021 · 1 comment · Fixed by #2710
Closed

ssz.Root.equals performance #2708

twoeths opened this issue Jun 16, 2021 · 1 comment · Fixed by #2710
Assignees
Labels
scope-performance Performance issue and ideas to improve performance.

Comments

@twoeths
Copy link
Contributor

twoeths commented Jun 16, 2021

Describe the bug

In the profiler result below, Root comparison and state.setStateCachesAsPersistent seems to be too high compared to others:

Screen Shot 2021-06-16 at 08 22 04

We need to analyse why and if we can improve it

Update

My other profiler shows that postState.setStateCachesAsPersistent(); is only 0.1ms (so we can iggnore it) while Root comparison is still that high (2.6ms)

@twoeths twoeths added the scope-performance Performance issue and ideas to improve performance. label Jun 16, 2021
@twoeths
Copy link
Contributor Author

twoeths commented Jun 16, 2021

Benchmark for Root equals check:
Currently block.stateRoot is tree backed

test ssz equal                                                         17778.09 ops/s      56.24900 us/op 264549 runs    15.01 s

If I use block.stateRoot.valueOf() as Uint8Array it's 3.5 times faster:

test ssz equal using valueOf()                                         63673.99 ops/s      15.70500 us/op 933370 runs    15.03 s

seems like this is related to ChainSafe/ssz#83

also, we use ssz.Root.equals() in a lot of places, we need to either apply the pattern to all places or fix the above ssz issue.

Update

byteArrayEquals is the winner, it's 40x faster

test ssz equal using byteArrayEquals                                   708215.3 ops/s      1.412000 us/op 8278979 runs    15.47 s

@twoeths twoeths self-assigned this Jun 16, 2021
@twoeths twoeths changed the title Investigate state transition performance ssz.Root.equals performance Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope-performance Performance issue and ideas to improve performance.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant