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

Review Buffer.from usage #6688

Closed
nflaig opened this issue Apr 19, 2024 · 0 comments · Fixed by #6723
Closed

Review Buffer.from usage #6688

nflaig opened this issue Apr 19, 2024 · 0 comments · Fixed by #6723
Labels
good first issue Issues that are suitable for first-time contributors. scope-performance Performance issue and ideas to improve performance.

Comments

@nflaig
Copy link
Member

nflaig commented Apr 19, 2024

Review how Buffer.from is used within Lodestar, and check the following:

  • is it required to convert to Buffer at all?
  • can we convert to Buffer without memory copy?
  • does it impact browser compatibility?

Eg. a good example of incorrect Buffer.from usage

value: Buffer.from(this.type.serialize(block)),

Which either should not be a Buffer at all as based on type a Uint8Array is valid, or if Buffer is required should avoid the memory copy.

Depending on the size of the Uint8Array, converting to Buffer with memory copy is quite expensive while without copy it's essentially free

From unstable...nflaig/bench-buffer-from

Buffer utils
✔ Buffer.from - copy                  7.286412 ops/s    137.2418 ms/op   x1.024         38 runs   5.82 s
✔ Buffer.from - no copy                1117318 ops/s    895.0000 ns/op   x0.982     723013 runs   1.11 s
✔ Buffer.from - no copy with offset    1179245 ops/s    848.0000 ns/op        -    2699558 runs   3.85 s

Related #6687

@nflaig nflaig added good first issue Issues that are suitable for first-time contributors. scope-performance Performance issue and ideas to improve performance. labels Apr 19, 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. scope-performance Performance issue and ideas to improve performance.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant