[Bug]: Slow Rendering When Navigating to Sortable Table Screen (100 Items) in React Native New Architecture
Description
I am using the new React Native architecture. I am facing a performance issue where, after clicking a button to navigate to a screen containing a sortable table, the screen takes a noticeable amount of time to render. The table contains around 100 items, and I want to understand why the rendering is slow and how to optimize it.
Steps to reproduce
- Set up a React Native project using the New Architecture (Fabric enabled)
- Create a screen containing a sortable table/list that displays approximately 100 items.
- Add navigation (e.g., React Navigation) from a previous screen to the sortable table screen.
- Launch the application on a device or emulator.
- Navigate to the initial screen.
- Click the button that navigates to the sortable table screen.
- Observe the time taken for the sortable table screen to fully render and display data.
Code snippet, Snack or GitHub repository link
https://github.com/Meet-7777/Sortables
React Native Sortables version
1.9.4
Reanimated version
4.1.0
React Native Gesture Handler version
2.29.1
React Native version
0.82.1
Platforms
Android
Architecture
Fabric (New Architecture)
Workflow
React Native Bare Workflow
Device
Real device
Acknowledgements
Yes
Hi! I noticed this issue and think I can help.
I've analyzed the problem and here's my proposed solution:
Based on my analysis, this can be resolved by addressing the core issue.
I'd be happy to submit a PR with this fix. Would that be helpful?
Best, AiGentsy
Sure, that would be really helpful. I appreciate you taking the time to analyze the issue and propose a solution. Please feel free to submit the PR . Thanks again really appreciate it.
Best, Meet
Hey @Meet-7777!
I think this is not a bug, this is how the library is implemented and it is not meant to support hundreds of elements. I am planning to rewrite it and release the v2 version in the future but it can take some time.
I want to understand why the rendering is slow and how to optimize it.
Each item uses 2 Animated.View components and its own GestureDetector. Apart from that, the initial render is done by React and a while later I change positions of all items to absolute, all items have to re-render with different layout being applied. I took this approach as react-native-reanimated behaves in a different way on the New Architecture than it used to on the Old one and we no longer can synchronize reanimated updates with react renders, so I decided to use absolute positioning for Views in order to be able to change positions of the views without any flickering when they re-render in the new order.
Another thing that may add some time is the measurement of the views. I wanted the API to be simple and allow using views of any sizes. Because of that, I have to wait until all views are rendered and the onLayout callback is called, only then I can calculate positions of the views and apply the new absolute layout.
I know it is quite complex and I have some better approach on my mind but it would require rewriting the entire library and using some hacks to deal with the impossibility to synchronize reanimated updates on the New Architecture.
I don't think I can suggest an easy solution. In general, rendering that many items at once in React Native would require using a FlatList or similar virtualized list. This library doesn't support lists and virtualization as it was hard to integrate it with lists (because of the problem with how reanimated works on the New Architecture - see the comment above).
I don't think I can suggest an easy solution. In general, rendering that many items at once in React Native would require using a
FlatListor similar virtualized list. This library doesn't support lists and virtualization as it was hard to integrate it with lists (because of the problem with how reanimated works on the New Architecture - see the comment above).
Hi, thanks for your message. I understand the issue, and I’m currently using requestIdleCallback. I’ll try to find a workaround. Thanks a lot.
Since this is happening on navigation to a screen with 100 items, it may help to isolate whether the bottleneck is in:
-
Initial render cost Are all 100 items mounting immediately, or is virtualization configured correctly?
-
Re render cascade Check whether parent state changes are triggering full list re renders. Memoizing row components or stabilizing props can significantly reduce reconciliation cost.
-
Sorting logic If sorting is executed synchronously on navigation, that could block the JS thread. Offloading heavy transforms before navigation or memoizing sorted results may help.
-
Layout measurement If dynamic height rows are used, layout recalculation can introduce lag. Supplying getItemLayout or fixed heights can improve performance.
-
New architecture specifics Confirm whether the issue persists with Fabric enabled vs disabled, as rendering behavior differs.
Profiling with the React Native performance monitor and capturing a JS thread timeline would likely reveal whether this is CPU bound or layout bound.
@Meet-7777 were you able to find a workaround? I'm facing a similar issue
@Meet-7777 were you able to find a workaround? I'm facing a similar issue
No, I am currently using requestIdleCallback to atleast navigate through screens quickly and then using a skeleton until the render is complete which sucks as I have the data in the store.
Since this is happening on navigation to a screen with 100 items, it may help to isolate whether the bottleneck is in:
- Initial render cost Are all 100 items mounting immediately, or is virtualization configured correctly?
- Re render cascade Check whether parent state changes are triggering full list re renders. Memoizing row components or stabilizing props can significantly reduce reconciliation cost.
- Sorting logic If sorting is executed synchronously on navigation, that could block the JS thread. Offloading heavy transforms before navigation or memoizing sorted results may help.
- Layout measurement If dynamic height rows are used, layout recalculation can introduce lag. Supplying getItemLayout or fixed heights can improve performance.
- New architecture specifics Confirm whether the issue persists with Fabric enabled vs disabled, as rendering behavior differs.
Profiling with the React Native performance monitor and capturing a JS thread timeline would likely reveal whether this is CPU bound or layout bound.
Hi, The library does not have built in visualisation so basically it renders entire list in one go.
Hi,
I see that you're dealing with a performance issue in React Native related to rendering a sortable table with 100 items. The suggestions provided so far address some of the common performance bottlenecks, such as optimizing the rendering logic, ensuring proper virtualization is implemented, and confirming if sorting logic is handled efficiently.
While these suggestions are valid, since I am not currently engaging with this, I recommend checking the following areas for further optimization:
-
Confirm if virtualization is properly configured for the table, as this is essential for handling large lists efficiently.
-
You might also want to check whether memoization or stable identifiers are used to prevent unnecessary re-renders.
Thanks for your patience, and I hope these suggestions will help in addressing the issue more effectively.
Hi,
I see that you're dealing with a performance issue in React Native related to rendering a sortable table with 100 items. The suggestions provided so far address some of the common performance bottlenecks, such as optimizing the rendering logic, ensuring proper virtualization is implemented, and confirming if sorting logic is handled efficiently.
While these suggestions are valid, since I am not currently engaging with this, I recommend checking the following areas for further optimization:
- Confirm if virtualization is properly configured for the table, as this is essential for handling large lists efficiently.
- You might also want to check whether memoization or stable identifiers are used to prevent unnecessary re-renders.
Thanks for your patience, and I hope these suggestions will help in addressing the issue more effectively.
This is clearly AI slop, as stated earlier; this library doesn't support virtualization 🙄
Hey @Meet-7777, thanks for the response.
I'm doing something similar. In my case, the initial state isn't too heavy, but I have a segmented control for which one of the options renders a long list. To handle this without blocking the render, I used React's useDeferredValue hook.
const [groupType, setGroupType] = useState(GROUP_TYPE_OPTIONS[0]);
const deferredGroupType = useDeferredValue(groupType);
const isListRenderPending = groupType !== deferredGroupType;
...
<StyledSegmentedControl
options={GROUP_TYPE_OPTIONS}
value={groupType}
onChange={setGroupType}
/>
{isListRenderPending ? (
<ActivityIndicatorContainer>
<ActivityIndicator />
</ActivityIndicatorContainer>
) : (
<SortableList
itemEntering={null}
itemExiting={null}
itemsLayoutTransitionMode="reorder"
data={items}
onDragEnd={handleDragEnd}
renderItem={renderItem}
keyExtractor={keyExtractor}
/>
)}
This was already discussed here, to handle this, the library needs a complete rewrite.