chore: change ByteArrayEquals to Buffer.compare()
Motivation The goal of this pull request is to improve the performance of byte array comparisons within the codebase by replacing the use of byteArrayEquals() with Node.jsâs built-in Buffer.compare(). This change is motivated by significant performance gains observed in benchmark tests, especially for larger data sets, such as mainnet Ethereum state objects.
Description
This PR replaces instances of byteArrayEquals() with Buffer.compare() for comparing byte arrays. Benchmark results demonstrate substantial improvements in speed:
For 32-byte arrays (commonly used for root equality checks), Buffer.compare() is over 2x faster than byteArrayEquals().
For large arrays (~100 MB), Buffer.compare() is approximately 22x faster.
Closes #5955
git checkout <Buffer_compare>
# Run benchmark or existing test suite to ensure no regressions
npm test
# Optionally run performance benchmarks
node benchmarks/compareBenchmark.js
@nflaig , pls could you review. i have made the changes required
@nflaig , pls could you review. i have made the changes required
you changed the title of the test, but the code still uses Buffer.compare inside the benchmark for byteArrayEquals
@nflaig , pls could you review. i have made the changes required
you changed the title of the test, but the code still uses
Buffer.compareinside the benchmark forbyteArrayEquals
Thanks, @nflaig i was in a hurry to push, an oversight on my part
putting as draft until CI is green
closing stale PR