react-native
                                
                                 react-native copied to clipboard
                                
                                    react-native copied to clipboard
                            
                            
                            
                        Optimize runtime initialization for native components with memoization
Summary:
This pull request introduces a memoization optimization in the getNativeComponentAttributes function to avoid redundant runtime initialization for native components. It introduces a memoization cache (configCache) to store previously computed configurations, which are then utilized if available before computing a new one.
Changelog:
[INTERNAL|GENERAL] [ADDED] - Introduced memoization optimization to getNativeComponentAttributes function.
Test Plan:
No changes to user interface. The code has been tested locally to ensure that previously computed configurations are utilized when available, reducing redundant computations.
| Fails | |
|---|---|
| :no_entry_sign: | :clipboard: Verify Changelog Format - See Changelog format | 
Generated by :no_entry_sign: dangerJS against 9e766f56efae53dc8a8312f45696e526b2853d8f
@dmytrorykun does this change make sense?
Good point @dmytrorykun, not really sure however I did fix my issue with patch-package locally in a project this way, see ref. below
@admirsaheta this error means that the LEGACY_RNCViewPager native component is not exported from native. Assuming you are on the old architecture, you should have either of the two:
- LEGACY_RNCViewPager, a subclass of- RCTViewManager, that has- RCT_EXPORT_MODULE()in its implementation.
- Some other RCTViewManagersubclass that hasRCT_EXPORT_MODULE(LEGACY_RNCViewPager)in its implementation.
I don't see how extra caching can fix this. Could that be some other change?
@admirsaheta you must pass useNext={false} to the pager view component, latest release of pager-view is a mess…
@admirsaheta you must pass
useNext={false}to the pager view component, latest release of pager-view is a mess…
This fixes it as well! Thank you 👍
While I did observe improvements locally using this approach, your question about the reduction of calls to UIManager.getViewManagerConfig raises valid concerns about the effectiveness of this optimization in real-world scenarios, still would consider it good practice to avoid unnecassary re-inits each time it's called 👍
@admirsaheta
While I did observe improvements locally using this approach
Could you describe the improvements in more details?
still would consider it good practice to avoid unnecassary re-inits each time it's called
Re-inits of what exactly? Are you seeing getNativeComponentAttributes being called for the same component multiple times?
Yes!
@admirsaheta could you please add more details, describe how you test this, and what is the improvement that you're seeing.
| Platform | Engine | Arch | Size (bytes) | Diff | 
|---|---|---|---|---|
| android | hermes | arm64-v8a | 21,234,731 | +7 | 
| android | hermes | armeabi-v7a | n/a | -- | 
| android | hermes | x86 | n/a | -- | 
| android | hermes | x86_64 | n/a | -- | 
| android | jsc | arm64-v8a | 24,431,921 | +4 | 
| android | jsc | armeabi-v7a | n/a | -- | 
| android | jsc | x86 | n/a | -- | 
| android | jsc | x86_64 | n/a | -- | 
Base commit: 8f98c58d384e71282a6147203bda84a095aba595 Branch: main