-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
fix: reuse Buffer instance #7016
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #7016 +/- ##
============================================
+ Coverage 49.23% 49.24% +0.01%
============================================
Files 578 578
Lines 37426 37438 +12
Branches 2165 2172 +7
============================================
+ Hits 18426 18437 +11
- Misses 18960 18961 +1
Partials 40 40 |
packages/utils/package.json
Outdated
@@ -27,7 +27,7 @@ | |||
"build:watch": "yarn run build --watch", | |||
"build:release": "yarn clean && yarn build", | |||
"check-build": "node -e \"(async function() { await import('./lib/index.js') })()\"", | |||
"check-types": "tsc && vitest --run --typecheck --dir test/types/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nflaig somehow this vitest command scans through the new test/perf
folder and it caused error, even after I added --exclude
option. Note that the benchmarks go with mocha
I guess it's still ok to drop this check because we also scan through unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to run type checks separately because of --typecheck
flag and those are not checked as part of unit tests. This seems to be an issue on vitest side, it shouldn't even scan files in this folder, I tried all possible options from here but none worked other than setting ignoreSourceErrors=true
which I think is ok here and only affect typecheck tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are few more places we could use toRootHex
should those be updated as well?
Eg.
lodestar/packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Lines 100 to 102 in 64fe1db
const blockRoot = toHex(chain.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(signedBlock.message)); | |
// bodyRoot should be the same to produced block | |
const bodyRoot = toHex(chain.config.getForkTypes(slot).BeaconBlockBody.hashTreeRoot(signedBlock.message.body)); |
// Shared buffer to convert root to hex | ||
const rootBuf = Buffer.alloc(32); | ||
|
||
export function toRootHex(root: Uint8Array): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if you pass in a root > 32 bytes? I would assume it just cuts of the end but we could consider throwing a more explicit error if this function is misused
the unstable mainnet node |
* fix: improve message id to string conversion * fix: use shared Buffers for sszBytes util * feat: implement toRootHex() * fix: lint and check-types * Fix type checks * Add comment to vitest config * Update packages/utils/src/bytes.ts --------- Co-authored-by: Nico Flaig <[email protected]> Co-authored-by: Cayman <[email protected]>
🎉 This PR is included in v1.22.0 🎉 |
Motivation
Buffer.from()
and then convert to hex/base64. We can just reuse same Buffer in that case that would help thegc
a lotDescription
msgIdToStrFn()
function by using the same BuffertoRootHex()
function using the same Buffer instance to compute RootHex from a RootsszBytes
util, for example to extract AttData base64gc