Repository navigation
Conversation
6071dca to
f3f282b
Compare
928574a to
4bd295c
Compare
|
|
||
| NativePropsHolder *getNativePropsHolder() const noexcept; | ||
| NativePropsHolder &getOrCreateNativePropsHolder() const; | ||
| mutable std::atomic<NativePropsHolder *> nativePropsHolder_{nullptr}; |
There was a problem hiding this comment.
why not store this as unique_ptr? so we can avoid the manual delete
There was a problem hiding this comment.
The pointer is atomic so that a clone can check it without the lock while setNativeProps creates the holder on another thread. A std::unique_ptr cannot be loaded atomically. If you prefer no delete, I can keep ownership in a unique_ptr next to the atomic pointer, which adds 8 bytes per family.
|
Is this really costly? we only recently changed this to be unique_ptr and a mutex should be |
4bd295c to
eb35272
Compare
|
I measured it in a Release build of the C++ tests on Apple M6, as median retired instructions over three processes:
Constructing the mutex costs nothing, as you say. The clone path is where most of the difference is. I updated the test plan with these numbers in place of the Debug ones. |
chrfalch
left a comment
There was a problem hiding this comment.
The lazy holder is correct as written. The compare-exchange in getOrCreateNativePropsHolder frees the losing allocation, the acquire load pairs with the acq_rel publish, and a clone that sees no holder behaves the same as a clone that took the old mutex just before setNativeProps. One point needs a decision: nativeProps_DEPRECATED and nativePropsMutex were public members of a public header, and this change makes them private. Any third-party C++ code that reads them stops compiling, so the PR needs a changelog entry, which it does not have yet, and that entry should say the change is breaking for C++ consumers. Two comments in ShadowNode::clone, outside the diff, still name family.nativeProps_DEPRECATED and are now stale.
Every `ShadowNodeFamily` carries a mutex for `setNativeProps`. Allocate the mutex and its props storage together on first use. Clones check whether the storage exists and acquire the mutex only when it does. The storage lives until the family is destroyed, and clones use it through a raw pointer, so it is private to `ShadowNodeFamily` and reached only by `ShadowNode` and `UIManager`. C++ code that reads `ShadowNodeFamily::nativeProps_DEPRECATED` or `ShadowNodeFamily::nativePropsMutex` no longer compiles. Such code sets native props with `UIManager::setNativeProps_DEPRECATED`, which commits a clone with the new values, and reads them from the shadow node's props. The C++ `ShadowNode`, `ShadowNodeFamily` and `UIManager` suites pass. The Fantom Mounting and ReactNativeElement suites also pass, including their `setNativeProps` cases. `python -m scripts.cxx-api.parser --validate` passes with Doxygen 1.16.1. In a Release build of the C++ tests on Apple M6, `sizeof(ShadowNodeFamily)` falls from 296 to 232 bytes, and on Android arm64 from 272 to 240 bytes. Across three processes, cloning a View without native props retires a median of 1,766 instructions before the change and 1,668 after it, and creating and destroying a View retires 4,761 to 4,829 before and 4,549 to 4,551 after. Signed-off-by: James Ide <ide@expo.dev>
eb35272 to
a38c7ff
Compare
|
Thanks for the review. I kept the two members private: a public pointer to the lazily created holder would let outside code free or replace it while a clone holds it. The changelog line is now |
Summary:
Every
ShadowNodeFamilycarries a mutex forsetNativeProps. Allocate the mutex and its props storage together on first use. Clones check whether the storage exists and acquire the mutex only when it does.The storage lives until the family is destroyed, and clones use it through a raw pointer, so it is private to
ShadowNodeFamilyand reached only byShadowNodeandUIManager. C++ code that readsShadowNodeFamily::nativeProps_DEPRECATEDorShadowNodeFamily::nativePropsMutexno longer compiles. Such code sets native props withUIManager::setNativeProps_DEPRECATED, which commits a clone with the new values, and reads them from the shadow node's props.Changelog:
[General] [Breaking] - Make
ShadowNodeFamily::nativeProps_DEPRECATEDandShadowNodeFamily::nativePropsMutexprivate; set native props withUIManager::setNativeProps_DEPRECATEDand read the applied values from the shadow node's propsTest Plan:
The C++
ShadowNode,ShadowNodeFamilyandUIManagersuites pass. The Fantom Mounting and ReactNativeElement suites also pass, including theirsetNativePropscases.python -m scripts.cxx-api.parser --validatepasses with Doxygen 1.16.1.In a Release build of the C++ tests on Apple M6,
sizeof(ShadowNodeFamily)falls from 296 to 232 bytes, and on Android arm64 from 272 to 240 bytes. Across three processes, cloning a View without native props retires a median of 1,766 instructions before the change and 1,668 after it, and creating and destroying a View retires 4,761 to 4,829 before and 4,549 to 4,551 after.