feat: add RCTArrayBuffer zero-copy class - #57879
Draft
paradowstack wants to merge 1 commit into
Draft
Conversation
paradowstack
force-pushed
the
feat/zero-copy-array-buffers-objc
branch
from
August 10, 2026 14:16
c37b919 to
c9fe284
Compare
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.
Summary:
iOS TurboModules mapped a JS
ArrayBuffertoNSDataon arguments andNSMutableDataon returns, so every crossing copied — andNSMutableDatacannot alias foreign memory, so there was no way to express "these bytes live somewhere else".This adds
RCTArrayBuffer(packages/react-native/React/Base/) as the ObjC representation of anArrayBuffer. It carries anisOwningBytesflag: an owning buffer can be stored and read from any thread, a non-owning one aliases bytes valid only for the synchronous call that produced it.Codegen now emits
RCTArrayBuffer *forArrayBufferTypeAnnotationparams (wasNSData *) and returns (wasNSMutableData *).Changelog:
[IOS] [ADDED] - Add
RCTArrayBuffer, the ObjC representation of a JSArrayBufferfor TurboModules, with an explicit byte-ownership contractTest Plan:
RCTTurboModuleArrayBufferTests— 9 tests over the sync in-place path,isOwningByteson a sync argument, returning one's own argument, the void/Promise copy paths, nesting, and a zero-length round trip.RCTTurboModuleTests.mmaddstestNativeBackedArrayBufferIsAliasedAndKeepsBackingStoreAlive.RCTSampleTurboModuledoubles its argument in place and returns the same buffer, covering the path end to end.