lodestar icon indicating copy to clipboard operation
lodestar copied to clipboard

chore: change ByteArrayEquals to Buffer.compare()

Open enyinnaya1234 opened this issue 7 months ago • 5 comments

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

enyinnaya1234 avatar May 23 '25 19:05 enyinnaya1234

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 23 '25 19:05 CLAassistant

@nflaig , pls could you review. i have made the changes required

enyinnaya1234 avatar May 23 '25 22:05 enyinnaya1234

@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 avatar May 23 '25 23:05 nflaig

@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

Thanks, @nflaig i was in a hurry to push, an oversight on my part

enyinnaya1234 avatar May 24 '25 03:05 enyinnaya1234

putting as draft until CI is green

nflaig avatar May 27 '25 16:05 nflaig

closing stale PR

wemeetagain avatar Sep 04 '25 15:09 wemeetagain