perf : Use GetStringRegion for JavaTurboModule string returns - #58611
riteshshukla04 wants to merge 2 commits into
Conversation
|
Cool idea! I wonder if there's higher impact areas for this beyond turbomodule return values (eg WritableNativeMap / WritableNativeArray) - and what the right max stack size to use is. |
|
Worth measuring too: the 2nd param to |
I checked the copy thing with the old code, |
Also I asked claude to create a quick POC accordingly. One more observation here is , we are using
|
javache
left a comment
There was a problem hiding this comment.
Can we use fbjni's JStringUtf16Extractor. That uses GetStringCritical, which probably performs even better.
Summary:
I changed the sync Java TurboModule string return path to copy the jstring with
GetStringRegioninto a 256 char stack buffer (heap above that), going from 3 JNI calls (GetStringLength,GetStringChars,ReleaseStringChars) -> 2 (GetStringLength,GetStringRegion) per call.I did 100_000 calls of
SampleTurboModule.getString(s)For some things like
NativeAppearance.getColorScheme()I got upto 19% improvement.The 256 number is just a POC. We can try 512 or 1024 or something. I am happy to discuss on this .
Changelog:
[ANDROID][CHANGED] - Use GetStringRegion for JavaTurboModule to reduce JNI calls from 3->2
Test Plan:
I ran maestro tests locally . Everything seems to pass.
I also asked claude to create a set of test cases with different string types(text, String , emojis) in turbo module to see nothing breaks