Skip to content

JArrayBuffer zero-copy class for Java TM - #57897

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

JArrayBuffer zero-copy class for Java TM#57897
paradowstack wants to merge 1 commit into
react:mainfrom
paradowstack:feat/zero-copy-array-buffers-java

Conversation

@paradowstack

@paradowstack paradowstack commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary:

Android TurboModules mapped a JS ArrayBuffer to java.nio.ByteBuffer, copying every argument into a direct buffer — and ByteBuffer carries no ownership contract, so there was no way to express aliased or borrowed bytes for synchronous in-place access.

This adds ArrayBuffer (packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ArrayBuffer.kt) as the Java representation of an ArrayBuffer. It carries an isOwningBytes flag: an owning buffer can be stored and returned to JS, a non-owning one aliases bytes valid only for the synchronous call that produced it.

Codegen now emits ArrayBuffer for ArrayBufferTypeAnnotation params (was ByteBuffer) and returns (was ByteBuffer).

Changelog:

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

Test Plan:

  • Codegen Java spec and JNI C++ snapshot tests updated for ArrayBuffer param/return signatures.
  • SampleTurboModule doubles its sync argument in place and returns the same buffer, covering the zero-copy path end to end; createNativeBuffer allocates via ArrayBuffer.
  • 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 11, 2026
@paradowstack
paradowstack force-pushed the feat/zero-copy-array-buffers-java branch from eb9740a to fab3a9f Compare August 12, 2026 13:06
@paradowstack paradowstack changed the title Zero-copy ArrayBuffer for Java TM JArrayBuffer zero-copy class for Java TM Aug 12, 2026
@paradowstack
paradowstack force-pushed the feat/zero-copy-array-buffers-java branch from fab3a9f to 44046b3 Compare August 12, 2026 13:18
@paradowstack
paradowstack marked this pull request as ready for review August 12, 2026 13:38
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