react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Optimize runtime initialization for native components with memoization

Open admirsaheta opened this issue 2 months ago • 9 comments

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.

admirsaheta avatar Apr 24 '24 19:04 admirsaheta

Fails
:no_entry_sign:

:clipboard: Verify Changelog Format - See Changelog format

Generated by :no_entry_sign: dangerJS against 9e766f56efae53dc8a8312f45696e526b2853d8f

github-actions[bot] avatar Apr 24 '24 19:04 github-actions[bot]

@dmytrorykun does this change make sense?

NickGerleman avatar Apr 26 '24 00:04 NickGerleman

Good point @dmytrorykun, not really sure however I did fix my issue with patch-package locally in a project this way, see ref. below image image

admirsaheta avatar Apr 28 '24 19:04 admirsaheta

@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:

  1. LEGACY_RNCViewPager, a subclass of RCTViewManager, that has RCT_EXPORT_MODULE() in its implementation.
  2. Some other RCTViewManager subclass that has RCT_EXPORT_MODULE(LEGACY_RNCViewPager) in its implementation.

I don't see how extra caching can fix this. Could that be some other change?

dmytrorykun avatar Apr 29 '24 09:04 dmytrorykun

@admirsaheta you must pass useNext={false} to the pager view component, latest release of pager-view is a mess…

efstathiosntonas avatar Apr 29 '24 09:04 efstathiosntonas

@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 avatar Apr 29 '24 09:04 admirsaheta

@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?

dmytrorykun avatar Apr 29 '24 09:04 dmytrorykun

Yes!

admirsaheta avatar Apr 29 '24 11:04 admirsaheta

@admirsaheta could you please add more details, describe how you test this, and what is the improvement that you're seeing.

dmytrorykun avatar Apr 29 '24 13:04 dmytrorykun