Skip to content

Commit ba1ede6

Browse files
riteshshukla04meta-codesync[bot]
authored andcommitted
perf: Faster WritableNativeMap.putString value conversion (#58644)
Summary: I found (while working on #58611) that `WritableNativeMap::putString` converted its value with fbjni toString(), which calls Java Object.toString() through JNI before running toStdString(). Since the value is already a `jstring`, I call `toStdString()` directly, which produces identical bytes with one fewer JNI call and local reference. | Value | Before | After | Delta | |---|---|---|---| | 11 ASCII | 0.205 | 0.191 | -6.8% | | 100 ASCII | 0.265 | 0.231 | -12.8% | | 300 ASCII | 0.451 | 0.418 | -7.3% | | 1000 ASCII | 0.984 | 0.966 | -1.8% | | 100 CJK | 0.325 | 0.298 | -8.3% | ## Changelog: [ANDROID] [CHANGED] - Skip a redundant JNI Object.toString() call in WritableNativeMap.putString. Pull Request resolved: #58644 Test Plan: I measured putString at 0.614 → 0.474 µs per call for short strings (-23%) on a Galaxy M14, identical output on 21 edge-case strings. Reviewed By: cortinico Differential Revision: D121774499 Pulled By: javache fbshipit-source-id: a20a3d64c6afaf75515f3c3e8173c8e86a1122ce
1 parent ec2b536 commit ba1ede6

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎packages/react-native/ReactAndroid/src/main/jni/react/jni/WritableNativeMap.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void WritableNativeMap::putString(std::string key, alias_ref<jstring> val) {
5555
return;
5656
}
5757
throwIfConsumed();
58-
map_.insert(std::move(key), val->toString());
58+
map_.insert(std::move(key), val->toStdString());
5959
}
6060

6161
void WritableNativeMap::putNativeArray(

0 commit comments

Comments
 (0)