Skip to content

JArrayBuffer zero-copy class for Java TM - #57897

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

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

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
@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 12, 2026
@meta-codesync

meta-codesync Bot commented Aug 12, 2026

Copy link
Copy Markdown

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

@meta-codesync

meta-codesync Bot commented Aug 17, 2026

Copy link
Copy Markdown

@christophpurrer merged this pull request in 5bb9639.

tvinhas pushed a commit to tvinhas/react-native-macos that referenced this pull request Oct 21, 2026
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

Pull Request resolved: react#57897

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.

Reviewed By: javache

Differential Revision: D115755247

Pulled By: christophpurrer

fbshipit-source-id: de067789ad145b7202da721a02f838358c82f4d8
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. Merged This PR has been merged. 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