Repository navigation
perf: avoid serialized copies of large worker buffers - #211
Merged
Merged
Conversation
Copy large fixed ArrayBuffers into existing ArrayBufferContents storage for single-recipient Worker and MessagePort sends. Move the copied contents to the receiver without detaching the source or serializing its payload again. Keep broadcast, stored and cross-process serialization reusable and preserve explicit-transfer handling. Cover shared backing references, marked source buffers, failed sends and independent broadcast copies.
Avoid constructing and destroying a second hash map for every serialized message. Single-recipient cloned contents require an empty transfer list, so their backing indexes can use the existing transfer map without changing object-pool numbering or detaching the source buffer.
steipete
marked this pull request as ready for review
October 25, 2026 15:43
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Large Worker messages copy ArrayBuffer payloads into the serialized byte vector, can copy that vector again when closing a container, and copy the payload into the receiver buffer. Use existing transferred-contents storage to hold one copy for a single-recipient send, then let the receiver adopt it.
Opt Worker and MessagePort sends into this path for fixed, nonshared ArrayBuffers of at least 16 KiB with no explicit transfer list. The source remains attached. Reuse the existing backing-index map, available because the mode excludes explicit transfers, without changing object-pool indexes. Broadcast serialization remains reusable; shared/resizable buffers and explicit transfers retain their handling. Stored and cross-process serialized bytes remain unchanged.
Qualified head:
20d214295042b7de88d5f0f9074fc067d5514289. The unchanged twelve-cell benchmark passes across three distinct quiet, on-demand Linux hosts, with ten interleaved pairs per cell and all 30 pairs retained. A/B used c7i.4xlarge; C used c7a.8xlarge after a c7i allocation timeout, before any C measurement. The separate session guard is 0.717122772 (limit 1.00). All 810 sample/control processes passed checksum/count and natural-exit checks.The first implementation failed the complete pool's small-error send cell at 1.036739333. Its observations are preserved. The follow-up removes the extra per-message map and receives the separate passing full pool above. No failed performance observation was rerun for green. A reservation-only diagnostic also failed; avoiding the trailer recopy alone was insufficient.
Validation on the qualified head:
The earlier wider native sweep had 775 passes, 47 existing skips and one pre-existing Worker entry-point builtin-alias diagnostic mismatch, reproduced with both published baselines. Its assertion and outcome remain unchanged.
Related upstream work: oven-sh/bun#46714 uses a different trailer-reservation approach. The measured slowdown is inside serialization's large-vector copy path; no unique upstream causative line within the broad sync was isolated. The separate macOS vmForks watchdog failure is not established to share this cause or be fixed by this change. No merge or release is included.