Skip to content

RCTArrayBuffer zero-copy class for ObjC TM - #57879

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

RCTArrayBuffer zero-copy class for ObjC TM#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
@paradowstack
paradowstack marked this pull request as ready for review August 11, 2026 06:28
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 11, 2026
@paradowstack paradowstack changed the title feat: add RCTArrayBuffer zero-copy class RCTArrayBuffer zero-copy class Aug 11, 2026
@paradowstack paradowstack changed the title RCTArrayBuffer zero-copy class RCTArrayBuffer zero-copy class for ObjC TM Aug 11, 2026
@meta-codesync

meta-codesync Bot commented Aug 11, 2026

Copy link
Copy Markdown

@christophpurrer has imported this pull request. If you are a Meta employee, you can view this in D115629409.

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 Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant