Repository navigation
Convert iOS native module objects to JS with fewer lookups and retains - #59450
Open
hryhoriiK97 wants to merge 1 commit into
Open
hryhoriiK97 wants to merge 1 commit into
hryhoriiK97 wants to merge 1 commit into
Conversation
TurboModule return values, promise results, callback arguments and codegen events are converted by convertObjCObjectToJSIValue. Dictionaries now read their keys and values at once instead of looking up each key again, keys are created as property names directly, nested values are retained once per container instead of once per call, and short strings without character storage are copied to the stack instead of the heap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Visual regressionNo visual differences at android: no capture |
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.
Summary:
TurboModuleConvertUtils::convertObjCObjectToJSIValueconverts native values to JS for TurboModule return values, promise results, callback arguments and codegen event emitters.Current behavior. For an
NSDictionary, it enumerates the keys and then looks up each value again withvalue[k]. Each key becomes ajsi::String, which the runtime then turns into a property name. Each nested value is retained and released at every level of the recursion. Short strings that CoreFoundation stores inside the pointer have no character storage, so they are copied into a heap-allocatedstd::u16string.With this change.
getObjects:andKeys:count:, and arrays withgetObjects:range:. The objects are retained once, in a vector, while they are converted, because JS code that runs while properties are set could change the container. Below that, the conversion doesn't retain each value again.jsi::PropNameID::forAsciiorforUtf16.JS receives the same values as before.
Changelog:
[IOS] [CHANGED] - Objects returned from native modules are converted to JS with fewer lookups and retains
Test Plan:
clang-format --dry-run --Werroron the changed file passes.xcodebuildin Release and run on a physical iPhone 15 Pro (iOS 26.6.1).NSDecimalNumber;NSNull,NSDateandNSURLvalues;NativeSampleTurboModulemethods in a loop. The calls include the unchanged conversion of the arguments from JS. The two arms are the same binary with the conversion switched by a launch argument, in alternating order: 8 launches without and 4 with this change. The presses were driven by Argent on the physical iPhone. iPhone 15 Pro, Release, medians per call:getObject, 20 keysgetObject, nested object like a keyboard eventgetObject, 3 keysgetValue(returns an object)The ranges of the two arms are separate for the first two rows and overlap for the last two. Calls that don't return objects are the same within noise.
🤖 Generated with Claude Code