Repository navigation
Conversation
The classic Fabric props parser registers each name a component reads and keeps a view of its bytes for later lookups. A `const char*` name leaves that lifetime requirement unstated, and every lookup measures a length the compiler already knows. This change adds `RawPropName` and uses it for the single-name `RawProps::at` and for `convertRawProp`. Its `consteval` constructor accepts string literals and static `constexpr` character arrays, so the compiler computes the length and the name has static storage. A name ends at its first NUL, or at the end of an array that has none. Generated code and calls that pass a literal keep their syntax. Names built at run time go through the new `RawProps::atRuntime`. The parser copies such a name when it registers it, and later lookups compare against the argument without copying it. The three-argument prefix and suffix overload of `RawProps::at` uses `atRuntime`. C++ code that passes a `const char*` or `std::string_view` name to `convertRawProp` or `RawProps::at` no longer compiles. A helper that forwards a declared name takes a `RawPropName` instead; code that builds a name at run time calls `atRuntime` and converts the returned `RawValue`. react#60541 proposes making the iterator-based setter the default for components that support it. That path hashes each supplied name and calls `setProp` without the registered names, so this change does not affect it. Components that use the classic constructor keep the registered-name path. `react_renderer_core_tests --gtest_filter='RawPropsTest.*:PropsConceptsTest.*:ComponentDescriptorTest.*'` passes in Debug. New tests look up a name without a terminating NUL and check that the parser copies composed names while it prepares. Compile-time checks accept string literals and reject `std::string`, `const char*` and `std::string_view` names. The Debug View and TextInput prop tests pass. The generated Safe Area props compile, and the Android NDK compiles the TextInput and View prop sources. `FANTOM_FORCE_OSS_BUILD=1 yarn fantom --maxWorkers=4` passes, including the View tests with the iterator flag on and off. `python -m scripts.cxx-api.parser --validate` passes with Doxygen 1.16.1. In an optimized build on an Apple M6, cloning `ViewProps` with six supplied props retires a median of 38,462 instructions on `075deb0d98` and 31,095 with this change on the classic path, 19.15% fewer. With the iterator flag on, the same clone retires 6,924 and 6,905.
The classic Fabric props parser registers each name a component reads and keeps a view of its bytes for later lookups. A `const char*` name leaves that lifetime requirement unstated, and every lookup measures a length the compiler already knows. This change adds `RawPropName` and uses it for the single-name `RawProps::at` and for `convertRawProp`. Its `consteval` constructor accepts string literals and static `constexpr` character arrays, so the compiler computes the length and the name has static storage. A name ends at its first NUL, or at the end of an array that has none. Generated code and calls that pass a literal keep their syntax. Names built at run time go through the new `RawProps::atRuntime`. The parser copies such a name when it registers it, and later lookups compare against the argument without copying it. The three-argument prefix and suffix overload of `RawProps::at` uses `atRuntime`. C++ code that passes a `const char*` or `std::string_view` name to `convertRawProp` or `RawProps::at` no longer compiles. A helper that forwards a declared name takes a `RawPropName` instead; code that builds a name at run time calls `atRuntime` and converts the returned `RawValue`. react#60541 proposes making the iterator-based setter the default for components that support it. That path hashes each supplied name and calls `setProp` without the registered names, so this change does not affect it. Components that use the classic constructor keep the registered-name path. `react_renderer_core_tests --gtest_filter='RawPropsTest.*:PropsConceptsTest.*:ComponentDescriptorTest.*'` passes in Debug. New tests look up a name without a terminating NUL and check that the parser copies composed names while it prepares. Compile-time checks accept string literals and reject `std::string`, `const char*` and `std::string_view` names. The Debug View and TextInput prop tests pass. The generated Safe Area props compile, and the Android NDK compiles the TextInput and View prop sources. `FANTOM_FORCE_OSS_BUILD=1 yarn fantom --maxWorkers=4` passes, including the View tests with the iterator flag on and off. `python -m scripts.cxx-api.parser --validate` passes with Doxygen 1.16.1. In an optimized build on an Apple M6, cloning `ViewProps` with six supplied props retires a median of 38,462 instructions on `075deb0d98` and 31,095 with this change on the classic path, 19.15% fewer. With the iterator flag on, the same clone retires 6,924 and 6,905.
The classic Fabric props parser registers each name a component reads and keeps a view of its bytes for later lookups. A `const char*` name leaves that lifetime requirement unstated, and every lookup measures a length the compiler already knows. This change adds `RawPropName` and uses it for the single-name `RawProps::at` and for `convertRawProp`. Its `consteval` constructor accepts string literals and static `constexpr` character arrays, so the compiler computes the length and the name has static storage. A name ends at its first NUL, or at the end of an array that has none. Generated code and calls that pass a literal keep their syntax. Names built at run time go through the new `RawProps::atRuntime`. The parser copies such a name when it registers it, and later lookups compare against the argument without copying it. The three-argument prefix and suffix overload of `RawProps::at` uses `atRuntime`. C++ code that passes a `const char*` or `std::string_view` name to `convertRawProp` or `RawProps::at` no longer compiles. A helper that forwards a declared name takes a `RawPropName` instead; code that builds a name at run time calls `atRuntime` and converts the returned `RawValue`. react#60541 proposes making the iterator-based setter the default for components that support it. That path hashes each supplied name and calls `setProp` without the registered names, so this change does not affect it. Components that use the classic constructor keep the registered-name path. `react_renderer_core_tests --gtest_filter='RawPropsTest.*:PropsConceptsTest.*:ComponentDescriptorTest.*'` passes in Debug. New tests look up a name without a terminating NUL and check that the parser copies composed names while it prepares. Compile-time checks accept string literals and reject `std::string`, `const char*` and `std::string_view` names. The Debug View and TextInput prop tests pass. The generated Safe Area props compile, and the Android NDK compiles the TextInput and View prop sources. `FANTOM_FORCE_OSS_BUILD=1 yarn fantom --maxWorkers=4` passes, including the View tests with the iterator flag on and off. `python -m scripts.cxx-api.parser --validate` passes with Doxygen 1.16.1. In an optimized build on an Apple M6, cloning `ViewProps` with six supplied props retires a median of 38,462 instructions on `075deb0d98` and 31,095 with this change on the classic path, 19.15% fewer. With the iterator flag on, the same clone retires 6,924 and 6,905. Signed-off-by: James Ide <ide@expo.dev>
|
We need to restart the experimental rollout around this at Meta - this previously regressed things. I have since refactored the constructor approach, but haven't restarted any experiments. |
chrfalch
left a comment
There was a problem hiding this comment.
The shouldRasterizeIOS fix is correct. Before this change, the iterator setter listened for a "shouldRasterize" key that JavaScript never sends, so that prop was silently dropped when the flag was on. Turning the flag on by default moves every core Props type that declares its own setProp to the iterator path. That includes Image, ScrollView, Text and TextInput, not only View and Paragraph. A rough comparison of the keys read by each constructor and by each setProp found no other gaps, but the new parity tests cover only View and Paragraph. A parity test for each of the other types would guard against the next mismatch like shouldRasterizeIOS. The main code comment is about the hand-written case, which re-indents about 60 unrelated lines.
The classic Fabric props parser registers each name a component reads and keeps a view of its bytes for later lookups. A `const char*` name leaves that lifetime requirement unstated, and every lookup measures a length the compiler already knows. This change adds `RawPropName` and uses it for the single-name `RawProps::at` and for `convertRawProp`. Its `consteval` constructor accepts string literals and static `constexpr` character arrays, so the compiler computes the length and the name has static storage. A name ends at its first NUL, or at the end of an array that has none. Generated code and calls that pass a literal keep their syntax. Names built at run time go through the new `RawProps::atRuntime`. The parser copies such a name when it registers it, and later lookups compare against the argument without copying it. The deprecated three-argument prefix and suffix overload of `RawProps::at` uses `atRuntime`, so the parser no longer keeps a view of the temporary string that overload composes. A Props constructor that reads its props only under a condition that was false while the parser was prepared leaves the parser with no registered names. A lookup in such a parser now returns `nullptr` instead of reading the first element of an empty name list. C++ code that passes a `const char*` or `std::string_view` name to `convertRawProp` or `RawProps::at` no longer compiles. A helper that forwards a declared name takes a `RawPropName` instead; code that builds a name at run time calls `RawProps::atRuntime` and converts the returned `RawValue`. react#60541 proposes making the iterator-based setter the default for components that support it. That path hashes each supplied name and calls `setProp` without the registered names, so this change does not affect it. Components that use the classic constructor keep the registered-name path. `react_renderer_core_tests --gtest_filter='RawPropsTest.*:PropsConceptsTest.*:ComponentDescriptorTest.*'` passes in Debug. New tests look up a name without a terminating NUL, check that the parser copies composed names while it prepares, and look up a name in a parser that registered none. Compile-time checks accept string literals and reject `std::string`, `const char*` and `std::string_view` names. The Debug View and TextInput prop tests pass. The generated Safe Area props compile, and the Android NDK compiles the TextInput and View prop sources. `FANTOM_FORCE_OSS_BUILD=1 yarn fantom --maxWorkers=4` passes, including the View tests with the iterator flag on and off. `python -m scripts.cxx-api.parser --validate` passes with Doxygen 1.16.1. In an optimized build on an Apple M6, cloning `ViewProps` with six supplied props retires a median of 38,462 instructions on `075deb0d98` and 31,095 with this change on the classic path, 19.15% fewer. With the iterator flag on, the same clone retires 6,924 and 6,905. Signed-off-by: James Ide <ide@expo.dev>
|
Thanks for the review. I added a parity test for each core Props type that supports the iterator setter: View, Paragraph, Text, Image, ScrollView and the cross-platform TextInput base. Each test gives a non-default value to every key that the type's own setter handles, checks that each value takes effect, and compares the two paths after setting the props and after removing them. The tests found three more mismatches, and this PR now fixes them. The TextInput setter ignored |
Enable `enableCppPropsIteratorSetter` by default. For components that support the iterator setter, Fabric copies the source props and calls `setProp` only for the supplied keys. Other components continue to use the classic constructor. Make the two paths agree for the core components that support the iterator setter. The View setter reads the public `shouldRasterizeIOS` key instead of `shouldRasterize`, which JavaScript never sends. The TextInput setter reads `minimumFontScale`, `lineBreak`, `wordBreak` and `experimental_textWidthMode`, as the classic constructor does; AndroidTextInput sends `minimumFontScale`. When JavaScript removes `width`, `height` or the ScrollView `horizontal` prop, the classic constructor now restores the declared default that the setter restores: `auto` instead of an undefined length, and `false` instead of `true`. Parity tests build View, Paragraph, Text, Image, ScrollView and the cross-platform TextInput props from the same values with the classic constructor and with the setter. Each test gives a non-default value to every key that the type's own setter handles (for View, a selection across its categories), checks that each value takes effect, and checks that the two paths agree after setting the values and after removing them. The tests live with their components and share a helper in `react/test_utils`. Reverting any of the fixes above, or removing the setter case of a tested key, fails the matching check. The Android setters of View, ScrollView, Paragraph and AndroidTextInput do not build on this host; a comparison of the keys that their constructors and setters read finds no difference. All ReactCommon C++ tests pass, built as the Fantom tester build does with this tree's generated code. A full `yarn fantom` run passes; two component-stack cases in `LogBox-itest.js` fail intermittently on this base with either flag value. The repository's C++ format check, `yarn flow-check` and `yarn lint` pass, and the C++ API snapshots validate. An optimized C++ benchmark on Apple M6 clones `ViewProps` with six supplied props through `ConcreteComponentDescriptor::cloneProps`, running one binary with each flag value. Median retired instructions fall from 38,432 to 6,893 per clone. Signed-off-by: James Ide <ide@expo.dev>
Summary:
Enable
enableCppPropsIteratorSetterby default. For components that support the iterator setter, Fabric copies the source props and callssetProponly for the supplied keys. Other components continue to use the classic constructor.Make the two paths agree for the core components that support the iterator setter. The View setter reads the public
shouldRasterizeIOSkey instead ofshouldRasterize, which JavaScript never sends. The TextInput setter readsminimumFontScale,lineBreak,wordBreakandexperimental_textWidthMode, as the classic constructor does; AndroidTextInput sendsminimumFontScale. When JavaScript removeswidth,heightor the ScrollViewhorizontalprop, the classic constructor now restores the declared default that the setter restores:autoinstead of an undefined length, andfalseinstead oftrue.Changelog:
[INTERNAL] [CHANGED] - Enable iterator-based props parsing for supported Fabric components.
[GENERAL] [FIXED] - Reset a removed ScrollView
horizontalprop tofalseand a removedwidthorheighttoauto, as the iterator setter does.Test Plan:
Parity tests build View, Paragraph, Text, Image, ScrollView and the cross-platform TextInput props from the same values with the classic constructor and with the setter. Each test gives a non-default value to every key that the type's own setter handles (for View, a selection across its categories), checks that each value takes effect, and checks that the two paths agree after setting the values and after removing them. The tests live with their components and share a helper in
react/test_utils. Reverting any of the fixes above, or removing the setter case of a tested key, fails the matching check. The Android setters of View, ScrollView, Paragraph and AndroidTextInput do not build on this host; a comparison of the keys that their constructors and setters read finds no difference.All ReactCommon C++ tests pass, built as the Fantom tester build does with this tree's generated code. A full
yarn fantomrun passes; two component-stack cases inLogBox-itest.jsfail intermittently on this base with either flag value. The repository's C++ format check,yarn flow-checkandyarn lintpass, and the C++ API snapshots validate.An optimized C++ benchmark on Apple M6 clones
ViewPropswith six supplied props throughConcreteComponentDescriptor::cloneProps, running one binary with each flag value. Median retired instructions fall from 38,432 to 6,893 per clone.