perf: remove redundant copies and JS boundary crossings on hot paths#1022
Open
connyay wants to merge 1 commit into
Open
perf: remove redundant copies and JS boundary crossings on hot paths#1022connyay wants to merge 1 commit into
connyay wants to merge 1 commit into
Conversation
- http/body.rs: Bytes::from(vec) instead of copy_from_slice, removing a second copy of every body chunk in the http-feature body bridge - d1: bind D1Type::Blob as an ArrayBuffer via Uint8Array (one memcpy) instead of serializing element-by-element into a JS number array - sql.rs: use js_sys::IteratorNext accessors instead of per-row Reflect::get with fresh key strings; drop the per-row Array.from copy in the raw cursor path - response.rs: Response::json() parses the buffered body in place instead of cloning it into a String via text() - response.rs: Response::cloned() duplicates fixed/empty bodies on the Rust side, reserving the JS Response.clone() tee for stream bodies Adds a D1 blob round-trip integration test (previously uncovered).
connyay
commented
Jul 7, 2026
| // D1's documented BLOB representation is an `ArrayBuffer`; copying | ||
| // through a `Uint8Array` crosses the JS boundary once instead of | ||
| // serializing element-by-element into a number array. | ||
| D1Type::Blob(a) => js_sys::Uint8Array::from(a).buffer().into(), |
Contributor
Author
There was a problem hiding this comment.
hmph. this is a good change, but might break some consumers. Worth a break here IMO
| .poll_next_unpin(cx) | ||
| .map_ok(|buf| { | ||
| let bytes = Bytes::copy_from_slice(&js_sys::Uint8Array::from(buf).to_vec()); | ||
| let bytes = Bytes::from(js_sys::Uint8Array::from(buf).to_vec()); |
Contributor
Author
There was a problem hiding this comment.
#1 win in the PR. Maybe worth breaking to its own PR if the rest of it is spooky/controversial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a D1 blob round-trip integration test (previously uncovered).