question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issues: all days always render on markedDate update

See original GitHub issue

When we use CalendarList with props markedDates={{}}, all days (basic/interactive) of all calendars will always re-render, even if there’s nothing to update. This is a problem for my app’s performances. (I use Agenda, and when items change, all calendar days re-render, + I’d like to provide custom markedDates)

Here are detected problems. I didn’t submit a PR because I’d like to discuss the potential solutions first. Once validated by the team I can submit a PR

Binding during render in Calendar, and using bound function in shouldComponentUpdate of Day:

onPress={this.pressDay.bind(this, day)}

If we bind, this means when calendar renders, all of its days will always render.

I think it’s fine to remove the prev.onPress !== next.onPress from the shouldComponentUpdate of the Day components.

Default marked props is not a constant

  getDateMarking(day) {
    if (!this.props.markedDates) {
      return false;
    }
    const dates = this.props.markedDates[day.toString('yyyy-MM-dd')] || [];
    if (dates.length || dates) {
      return dates;
    } else {
      return false;
    }
  }

The [] part is a problem because if a day has no explicit marking, it will always be a new objet, triggering re-rendering of the day.

One very simple solution is to use a constant element and instead to const dates = this.props.markedDates[day.toString('yyyy-MM-dd')] || EmptyArray;

By the way, I don’t really understand why we pass an empty array here. marked accepting array prop seems to me like a hack to quickly be compatible with Agenda’s items shape, but wouldn’t it make more sense to pass an empty object as default?

No optimization on CalendarList

The calendar list should not pass all markedDays for every calendar. Instead it should rather only pass to a calendar the marked days of the calendar’s month, so that the calendar component could choose to not render

This is probably less important and more tricky optimization

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sibeliuscommented, Sep 14, 2017

@tautvilas also check this https://github.com/wix/react-native-calendars/pull/175

it could improve a little bit as well

1reaction
tautvilascommented, Sep 14, 2017

CalendarList has been migrated to FlatList in 1.6.0 , this might improve performance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging React performance issues with Why Did You Render
Learn how to detect and resolve performance issues in React easily using the library Why Did You Render.
Read more >
@trucksmarter/react-native-calendars - npm
React Native Calendars 🗓️. Version Build Status. This module includes various customizable React-Native calendar components.
Read more >
TABLE OF CONTENTS - District Council 20
Days in this agreement are defined as calendar days unless otherwise ... representing the interests of all employees in the bargaining unit without....
Read more >
Fix the slow render before you fix the re-render - Kent C. Dodds
If we batch all DOM updates, then we can reduce the performance issues of updating the DOM multiple times in rapid succession. So...
Read more >
The Oklahoma Health Care Authority SoonerSelect ... - Oklahoma.gov
All RFP-related inquiries must be directed to this individual. ... Process for identifying, reporting, and remediating performance issues.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found