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

Update hexSlice to use TypedArrays and TextDecoder for large speed gains #367

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jawj
Copy link

@jawj jawj commented Dec 12, 2024

Following up on #364 and #366, this patch switches the hexSlice implementation to use TypedArrays and TextDecoder. It also adds a performance benchmark for toString('hex').

In Node on an M3 Pro MacBook, the benchmark shows a 5x speed-up on a 4096-byte buffer, achieving 75% of the speed of the native method. The speed-up is generally larger as the buffer size increases.

Before:

BrowserBuffer#toString("hex") x 72,483 ops/sec ±0.19% (99 runs sampled)
NodeBuffer#toString("hex") x 527,266 ops/sec ±0.33% (97 runs sampled)
Fastest is NodeBuffer#toString("hex")

After:

BrowserBuffer#toString("hex") x 403,058 ops/sec ±0.30% (98 runs sampled)
NodeBuffer#toString("hex") x 533,325 ops/sec ±0.21% (98 runs sampled)
Fastest is NodeBuffer#toString("hex")

@jawj
Copy link
Author

jawj commented Dec 19, 2024

@dcousens Any chance of merging this in the near future? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant