New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Too slow with higher numberOfMonths #1473
Comments
I tested it and is also slow on mobile devices, this bug will be fixed @gpbl ? |
It seems the calls of
are behind the performance issue. From there, we could investigate why these lines are so slow: react-day-picker/packages/react-day-picker/src/hooks/useDayRender/useDayRender.tsx Lines 52 to 74 in 1390898
I also suspect we could reduce the calls of react-day-picker/packages/react-day-picker/src/contexts/Modifiers/utils/getActiveModifiers.ts Line 18 in 5b9f24b
So far I haven't made any actual progress tho... @jech33 @rachanee-tw could you see why it is that slow? |
Any update on that performance issue ? |
Still face the issue, any suggestion? |
I've investigated where it goes slow and it is because functions and hooks that are called for each day cell. When rendering a whole year, there are lot of cells to render, thus the performance issue is more visible. There are for sure workarounds for the existing components, but I'd rather spend the time on something that fixes the issue at the root. At the moment, I'm playing with the idea where the date calculations would happen at root level (once, before rendering) and not at day level. This would give space for some better debugging (where it is actually slow?) and improvements. Some other ideas? |
I investigated and found the similar clue that hooks cause rerendering in multiple levels. I think splitting states to multiple hooks and useMemo may be able to help. But by my low level of understanding of the code base I might be wrong. |
I've been playing with I think that moving up these function calls (from the import { DayPickerProps } from 'DayPicker';
/** Represent the current state of DayPicker */
export interface DayPickerState {
initialProps: DayPickerProps;
modifiers: {
selected: Date[];
interactive: Date[];
focused: Date[];
disabled: Date[];
hidden: Date[];
outside: Date[];
today: [Date];
rangeStart: [Date];
rangeEnd: Date[];
};
customModifiers: {
[name: string]: Date[];
};
navigation: {
currentMonth: Date;
displayMonths: Date[];
nextMonth?: Date;
previousMonth?: Date;
};
} Thanks @rachanee-tw for the help! |
Relevant Issue
#374
Description
When setting the
numberOfMonths
to a higher value like 10, the performance when selecting dates is really slow, it takes a lot slower than using a lower value like 2.To reproduce
Fork this CodeSandbox: https://codesandbox.io/s/sandpack-project-forked-pzx9no?file=/App.tsx.
Steps
numberOfMonths
to be 1 and compare how much different.The text was updated successfully, but these errors were encountered: