Skip to content

Commit 2ec5eb4

Browse files
javachemeta-codesync[bot]
authored andcommitted
Skip RawPropsParser::prepare<T>() when the iterator-setter path is active (#57329)
Summary: Pull Request resolved: #57329 `RawPropsParser::prepare<ConcreteProps>()` runs in `ConcreteComponentDescriptor`'s constructor and builds the parser's `keys_` vector + `nameToIndex_` length-bucketed map by walking every `convertRawProp` call in a probe construction of `ConcreteProps`. The cost is O(n²) in the number of props (the comment in `RawPropsParser::at` notes 4950 lookups for a 100-prop class) and is paid once per component class at app startup. Those data structures are consumed **only** by `RawProps::at()`, which is reached exclusively through the classic per-field `convertRawProp` path. The iterator-setter path skips `parse()` entirely (see the prior diff in the stack), so the prepared parser is dead weight when both: 1. `HasIteratorSetterCtor<ConcreteProps>` is satisfied (i.e. the type opts into the iterator-setter path), AND 2. `enableCppPropsIteratorSetter()` is on at runtime. Guard the call accordingly. Classes that don't satisfy the concept always run `prepare<T>()` (they can only use the classic path); when the runtime flag is off, all classes run it (since they all fall back to classic). Changelog: [Internal] Differential Revision: D109569571
1 parent 321fcde commit 2ec5eb4

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
4848
RawPropsParser &&rawPropsParser = {})
4949
: ComponentDescriptor(parameters, std::move(rawPropsParser))
5050
{
51-
rawPropsParser_.prepare<ConcreteProps>();
51+
// The parser's `keys_` / `nameToIndex_` are only consumed by
52+
// `RawProps::at()`, which is reached exclusively through the classic
53+
// per-field `convertRawProp` path. When `ConcreteProps` opts into the
54+
// iterator-setter path and the runtime flag is on, `parse()` is never
55+
// called, so the O(n²) preparation here is wasted. Skip it.
56+
if constexpr (HasIteratorSetterCtor<ConcreteProps>) {
57+
if (!ReactNativeFeatureFlags::enableCppPropsIteratorSetter()) {
58+
rawPropsParser_.prepare<ConcreteProps>();
59+
}
60+
} else {
61+
rawPropsParser_.prepare<ConcreteProps>();
62+
}
5263
}
5364

5465
ComponentHandle getComponentHandle() const override

0 commit comments

Comments
 (0)