Skip to content

Represent classic Fabric prop names as static identifiers - #60539

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/raw-prop-name-length
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/raw-prop-name-length

Conversation

@ide

@ide ide commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

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.

#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.

Changelog:

[General] [Breaking] - Require string literal or static constexpr names in convertRawProp and RawProps::at; pass a name built at run time to RawProps::atRuntime instead

Test Plan:

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.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
@ide
ide force-pushed the @ide/raw-prop-name-length branch from 8d6cb13 to 46faf17 Compare December 4, 2026 09:51
@ide ide changed the title Pass the length of known RawProps keys Represent classic Fabric prop names as static identifiers Dec 4, 2026
@ide
ide force-pushed the @ide/raw-prop-name-length branch 2 times, most recently from 6a2ed1a to 5058ed1 Compare December 4, 2026 12:35
@ide
ide marked this pull request as ready for review December 4, 2026 14:27

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The design is sound. A consteval RawPropName makes the lifetime of names stored in the parser a compile-time guarantee, and atRuntime plus the shared owned-key storage fixes a real dangling view: before this change the prefix and suffix overload of RawProps::at stored a view of a temporary std::string in keys_. All in-repo callers and the codegen output pass literals, so the repository itself compiles unchanged. This is a source-breaking change for third-party Fabric components whose C++ passes a const char* or std::string_view name to convertRawProp or RawProps::at, so the description needs a changelog entry tagged [General] [Breaking] that names the atRuntime replacement; it currently has no changelog section.

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>
@ide
ide force-pushed the @ide/raw-prop-name-length branch from 5058ed1 to 5241193 Compare December 5, 2026 08:30
@ide

ide commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The description already had a [GENERAL] [BREAKING] line; the commit message has no changelog section. I reworded the line so that it names the replacement: "Require string literal or static constexpr names in convertRawProp and RawProps::at; pass a name built at run time to RawProps::atRuntime instead". The summary now also says that the prefix and suffix overload no longer leaves the parser with a view of the temporary string it composes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants