Have node-internal Buffer use JsUint8Array instead of BufferSource#6326
Have node-internal Buffer use JsUint8Array instead of BufferSource#6326
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR replaces jsg::BufferSource / jsg::BackingStore with jsg::JsUint8Array throughout the node-internal Buffer and i18n code, reducing overhead by operating directly on V8 typed-array handles.
Findings (highest severity first):
- [HIGH]
JsUint8Array::createuses V8's 2-argumentNewBackingStorewhich crashes on OOM instead of returning a catchable JS error. - [LOW] Incomplete conversion in
decode():state.asArrayPtr()used instead of the already-availablestatePtrlocal.
This review was generated by an AI assistant and may contain inaccuracies. Please verify all suggestions before applying.
This comment was marked as outdated.
This comment was marked as outdated.
551abeb to
5a67f82
Compare
02ce8ea to
3f2ac4d
Compare
|
/bigbonk update your review |
There was a problem hiding this comment.
Corrected my two earlier findings — both were inaccurate (the code was already correct). One actual nit in flush().
- [LOW]
flush()callsstate.asArrayPtr()3 times before definingstatePtron line 787. Moving the local up would be consistent with the pattern indecode().
This review was generated by an AI assistant and may contain inaccuracies. Please verify all suggestions before applying.
|
Done. Here's a summary of what I did: Re-review of PR #6326 On re-examination, both of my original findings were inaccurate:
I posted corrections as replies to both original comment threads, returning the undeserved cookies. Actual finding: The |
Use of `BufferSource` has too much overhead for the way that node-internal `Buffer` is used.
3f2ac4d to
73265fb
Compare
|
/bigbonk roast this pr |
There was a problem hiding this comment.
One low-severity finding on error type consistency.
- [LOW]
JsUint8Array::createthrows a genericErroron OOM, whileLock::allocBackingStorethrowsRangeError. Inline comment posted.
This review was generated by an AI assistant and may contain inaccuracies. Please verify all suggestions before applying.
| v8::BackingStoreOnFailureMode::kReturnNull); | ||
| if (!backing) { | ||
| js.v8Isolate->ThrowError(js.str("Failed to allocate memory for Uint8Array"_kj)); | ||
| throw jsg::JsExceptionThrown(); |
There was a problem hiding this comment.
Lock::allocBackingStore (used by the old BackingStore::alloc path) throws a RangeError on allocation failure:
JSG_REQUIRE(store != nullptr, RangeError, "Failed to allocate ArrayBuffer backing store");The new code here uses v8::Isolate::ThrowError, which throws a generic Error. If any user code catches RangeError specifically on large Buffer.alloc() calls, this would be a behavioral change.
Consider using JSG_REQUIRE for consistency:
| throw jsg::JsExceptionThrown(); | |
| if (!backing) { | |
| JSG_FAIL_REQUIRE(RangeError, "Failed to allocate memory for Uint8Array"); | |
| } |
|
Review posted successfully to PR #6326. Here's a summary of what I found: Re-review of PR #6326 The PR is a clean, well-structured conversion from Finding:
Items I verified as correct:
|
Use of
BufferSourcehas too much overhead for the way that node-internalBufferis used.A precursor to converting it all to rust.