react-native-big-calendar: Slows down when updating the 'events' array with many events
I’ve noticed that there is longer rendering time as the number of items in the events prop increases. I recorded a video when there’s a low and high number of events so show the difference.
From what I understand, day events are render in this part https://github.com/acro5piano/react-native-big-calendar/blob/master/src/components/CalendarBody.tsx#L158-L165
I haven’t done any performance measuring to understand where the time is spend to re-render.
Maybe it’s React that takes time to render a large list of items on the screen, so maybe there’s nothing we can do. Does anyone have any suggestions for something to try or trying another way to render the items? I’m happy to spend time on it but I’m not sure what to try so opening this issue for discussion…
Video with a high number of events (slows 2 seconds wait time to appear)
Video with a low number of events
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (11 by maintainers)
Commits related to this issue
- Merge pull request #714 from fabrianibrahim/main Improve performance - Fixing issue #563 — committed to acro5piano/react-native-big-calendar by acro5piano 4 years ago
After experiencing a slowdown in month view with many events, as described, profiling pointed to a large proportion of time spent in sort, which appears to be due to the order of the
sortandfilterin the month view: https://github.com/acro5piano/react-native-big-calendar/blob/f738fc36d67533e3dbdcc9c4b1e2d0dfb5e7a5e8/src/components/CalendarBodyForMonthView.tsx#L175-L190That is: all events are being sorted for every day rendered, not just the events that fall on that day. Re-ordering these calls so the sort only happens after filtering to the events that fall on the day resulted in a very appreciable speed up.
Additionally, converting the
sortandfilterfunctions there to use date-fns instead of dayjs and pre-calculating the duration in seconds for each event resulted in a further speed up, to the point where the monthly view is usable with a large number of events.@arisyo13 's PR is merged and released on v4.16.1. Let me summerize what’s happended:
We have the event overlapping feature. The logic is checking every events, then find overlapping event(s) and count them. The previous logic was too naive, causing the performance issue if there are lots of events. Its time complexity was
O(n^2). WhileO(n^2)looks okay for such a UI component, but actually there are comparison two dates (start end end) for each events, which is not silly.His tuning resolved the time complexity by binary search to find overlapping events. It makes the logic efficient enough to be
O(log n). Also, the loop now breaks once future events are found, because the events are sorted by time.Correct me if I’m wrong.
Let me close this issue. According to his benchmark, rendering 500 events used to took
62 secondsbut now it takes430 millisecondswhich is really fast. Big thank you for @arisyo13 again!i opened this pr https://github.com/acro5piano/react-native-big-calendar/pull/1124
@arisyo13 Please let us know if you find a way to optimize it! 🙏🏼
Im working on this. expect a PR soon
I also have this problem in mode “week”
I have same problem. Tested with both Android and iOS. Changing month, event click and everything slows down very much (takes 4-5s) when event array contains many event.
In my case, I have 98 entries in a single month. Here’s the snippet from code -
Please can anyone confirm if it works correctly for them on Android/iOS with about 100 events?
Thank you.