Skip to content

feat: add RCTArrayBuffer zero-copy class - #57879

Draft
paradowstack wants to merge 1 commit into
react:mainfrom
paradowstack:feat/zero-copy-array-buffers-objc
Draft

feat: add RCTArrayBuffer zero-copy class#57879
paradowstack wants to merge 1 commit into
react:mainfrom
paradowstack:feat/zero-copy-array-buffers-objc

Conversation

@paradowstack

Copy link
Copy Markdown
Contributor

Summary:

iOS TurboModules mapped a JS ArrayBuffer to NSData on arguments and NSMutableData on returns, so every crossing copied — and NSMutableData cannot 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 an ArrayBuffer. It carries an isOwningBytes flag: 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 * for ArrayBufferTypeAnnotation params (was NSData *) and returns (was NSMutableData *).

Changelog:

[IOS] [ADDED] - Add RCTArrayBuffer, the ObjC representation of a JS ArrayBuffer for TurboModules, with an explicit byte-ownership contract

Test Plan:

  • RCTTurboModuleArrayBufferTests — 9 tests over the sync in-place path, isOwningBytes on a sync argument, returning one's own argument, the void/Promise copy paths, nesting, and a zero-length round trip.
  • RCTTurboModuleTests.mm adds testNativeBackedArrayBufferIsAliasedAndKeepsBackingStoreAlive.
  • RCTSampleTurboModule doubles its argument in place and returns the same buffer, covering the path end to end.
  • Codegen and C++ API snapshots regenerated.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 10, 2026
@paradowstack
paradowstack force-pushed the feat/zero-copy-array-buffers-objc branch from c37b919 to c9fe284 Compare August 10, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant