Skip to content

perf(android): bridge UInt64 arrays as ULongArray - #1997

Open
mrousavy wants to merge 1 commit into
v1from
mrousavy/v1-kotlin-ulongarray
Open

mrousavy wants to merge 1 commit into
v1from
mrousavy/v1-kotlin-ulongarray

Conversation

@mrousavy

@mrousavy mrousavy commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

First of five stacked PRs: #1997 (this one) → #1998 → #1999 → #2008 → #2009.

Kotlin exposed UInt64[] as Array<ULong> while JNI carries a long[], so every crossing copied the array and boxed each element. Generated structs copied it again each time C++ read the field.

UInt64[] is now ULongArray, a value class over LongArray. Bridges convert with asLongArray() and asULongArray(), which reuse the same array, and JNI reads struct fields directly because a ULongArray field is a long[]. UInt64[][] becomes Array<ULongArray> and only the outer array is mapped. ULongArray boxes compare by identity, so generated structs compare these fields through their long[]. The mapToLongArray helpers in nitro-core have no callers left and are removed.

This changes the Kotlin type of every UInt64[] API from Array<ULong> to ULongArray. ULongArray still requires opting in to ExperimentalUnsignedTypes, and Kotlin warns without it. The generated +autolinking.gradle, which every Nitro module applies, now opts the module in with languageSettings.optIn('kotlin.ExperimentalUnsignedTypes'). That covers the generated code and the module's own spec implementations; only other modules that use these APIs, such as the app, need their own opt-in. The arrays docs say so.

New TestObject methods pass UInt64[] as a parameter, nested and optional arrays, a Promise result and callback values, with values above 2^63.

Validation: nitro-core, nitro-test and nitro-test-external Kotlin compile without warnings (152 opt-in warnings without the Gradle block), and the changed JNI sources compile with the NDK (syntax only, the Hermes submodule wasn't checked out). I did not run the runtime tests locally.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro-docs Ready Ready Preview Oct 23, 2026 5:51pm UTC

Request Review

@mrousavy
mrousavy added this pull request to stack #2000 October 23, 2026 12:23
@mrousavy mrousavy changed the title mrousavy/v1 kotlin ulongarray perf(android): bridge UInt64 arrays as ULongArray Oct 23, 2026
@mrousavy
mrousavy force-pushed the mrousavy/v1-kotlin-ulongarray branch from 035e0ad to 8d57d32 Compare October 23, 2026 17:36
Kotlin exposed UInt64[] as Array<ULong> while JNI carries a long[], so
every crossing copied the array and boxed each element. Generated
structs copied it again each time C++ read the field.

UInt64[] is now ULongArray, a value class over LongArray, and the bridge
converts it with asLongArray() and asULongArray(), which reuse the same
array. Struct fields hold the long[] that JNI reads directly.
UInt64[][] becomes Array<ULongArray>, so only the outer array is mapped.
The mapToLongArray helpers in nitro-core have no callers left and are
removed.

ULongArray still requires opting in to ExperimentalUnsignedTypes, and
Kotlin warns without it. The generated +autolinking.gradle opts each
Nitro module in, which covers generated code and the module's own spec
implementations. ULongArray boxes compare by identity, so generated
structs compare these fields through their long[].

New TestObject methods pass UInt64 arrays as parameters, nested and
optional arrays, Promise results and callback values.

This branch was successfully deployed

1 active deployment
Preview — ae0d1bcd Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant