Repository navigation
perf(android): pass strings across the bridge as UTF-16 - #122
Open
ammarahm-ed wants to merge 1 commit into
Open
ammarahm-ed wants to merge 1 commit into
ammarahm-ed wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Strings cross the JNI bridge as UTF-16 in both directions, in the Node-API and the direct runtime.
JS to Java.
ConvertToJavaStringread the string as UTF-8 into anew char[]that was never freed, then passed it toNewStringUTF. That leaked a buffer on every string argument (the Node-API heap below), andNewStringUTFtakes modified UTF-8, so non-BMP characters came out wrong. It now copies the UTF-16 code units into a stack buffer (heap only past 256 units) and callsNewString.Java to JS.
jstringToJsStringnow readsGetStringCharsinstead of re-encoding throughGetStringUTFChars. Acharreturn, field read and array element no longer build ajava.lang.Stringfirst.Engine layer. The direct runtime gets
Value::createStringFromUtf16andValue::copyUtf16on V8 (NewFromTwoByte/WriteV2), JSC (JSStringCreateWithCharacters/JSStringGetCharactersPtr), QuickJS-NG (JS_NewStringUTF16/JS_ToCStringLenUTF16) and Hermes (jsi::String::createFromUtf16/getStringData), which replaces the hand-written UTF-16 to UTF-8 transcoder inArgConverter.cpp. Unpaired surrogates survive the round trip.JSC.
JSString::CopyToinvendor/jsc/jsc-api.cppcopiedsizebytes instead ofsize * sizeof(JSChar), sonapi_get_value_string_utf16returned half a string.Results
V8 release build on a Sony SO-01M (Android 11, arm64), AOT-compiled with
cmd package compile -m speed. One warm-up launch is discarded, then 5 launches; values are the median ns per call.Rows this change does not touch moved by up to ±15% between runs (array and object returns by up to ±26%), which is this device's noise floor; only changes well beyond that are attributable.
All cases
Only V8 was built and run for this table. The JSC, QuickJS-NG and Hermes backends in this change have not been built or run yet.