-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
onOutsideRange constantly and needlessly recomputes thousands of time #245
Comments
That caching pattern wouldn't work though if the value needed to change on the same day - ie, let's say after 3PM, "today" becomes invalid. I think it's up to the creator of |
I feel like the tradeoff of not having split second precision for the date picker by doing something like only running recalculation to when the picker updates (e.g. not when you hover over dates) would be worth the performance gain. So if the user idles on the page, and the system time hits 3:01PM, it won't invalidate until the next render cycle? |
Correct - but any user interaction (like hovering) would immediately invalidate it. The point of a user providing a custom |
After looking into the code, it seems that To me it seems that of the modifiers, some only depend on external props (e.g. So as an example, maybe const hoverModifiersForDay = hoverChanged ? getModifiersForDay(hoverModifiers, day) : cachedHoverModifiers;
const selectModifiersForDay = selectedDatesChanged ? getModifiersForDay(selectModifiers, day); Where Do you think this is viable? If so, I can work on this. |
Hi @timhwang21, I think that #217 should fix at least some of these duplicated calls. My original thought is that we can't guarantee that How would If we could make this logic happen in the |
Hi, thanks for the response @majapw ! I'm glad that the 4x render issue is addressed -- that was bothering me as well (though it doesn't nearly impact performance as much). I did consider the fact that Speaking purely from personal opinion, I would say that if a user 1. uses hover state to determine date validity, or 2. puts hover logic in modifiers that shouldn't use them, and their widget subsequently breaks (e.g. the validation doesn't run when the user wants it to), this would be working as intended :) I'm not very familiar with the code base so I don't want to comment with any certainty, but from what I saw, the logic of mapping the modifiers over every single day happens in |
I'm with @timhwang21 on this one, I don't see any reason to modify the values on hover and the performance improvements would be amazing if we could stop re-calculating all the time :) Currently |
v11.0.0 (I swear the last breaking release for a while) rearchitects modifiers so now there's about the same overhead at mount, but then calendar interactions only updates the relevant You can see more details in #450, but in the meantime, I'm going to close this issue of being "generally slow". There are still some improvements to be made, notably during the month transition phase, but I think this new architecture opens up a lot of doors. :) |
It looks like
onOutsideRange()
is recomputed for EVERY SINGLE DATE every single time the datepicker is interacted with, be it clicking, or even hovering over dates.My test function:
The result:
When opening the datepicker for the first time (clicking an input), Chrome debugger logs up to 2519:
When the mouse enters or leaves any calendar date, Chrome debugger logs an additional 560 (18 months worth of days?) calls. Finally, subsequent closing / opening of the datepicker logs an additional 160 calls (560 * 3, significant?)
If the
isOutsideRange()
function is anything more than trivial, this results in a very noticeable performance slowdown.Ideally, the result of
isOutsideRange()
should be cached for each day, or should only be calculated for localized days, e.g. for all the dates currently visible ± 7 days (to account for outside days).The text was updated successfully, but these errors were encountered: