Skip to content
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

Cache some moment instances when rebuilding modifiers #1663

Merged
merged 1 commit into from
May 31, 2019
Merged

Conversation

lencioni
Copy link
Contributor

@lencioni lencioni commented May 31, 2019

When modifiers need to be rebuilt, which happens pretty frequently, we
iterate over every day and create a new moment instance for these
operations. These moment instances are never mutated, so we can safely
store and reuse them to improve performance.

This optimization reduces the time spent in
DayPickerRangeController#componentWillReceiveProps when selecting dates
from ~16ms to ~6-10ms.

Before:
image

After:
image

And here it is with a production build with 4x CPU slowdown.

Before:
image

After:
image

@lencioni lencioni added semver-patch: fixes/refactors/etc Anything that's not major or minor. performance labels May 31, 2019
@coveralls
Copy link

coveralls commented May 31, 2019

Coverage Status

Coverage increased (+0.03%) to 84.346% when pulling a60a76a on pooled-moment into 2e1dd23 on master.

@lencioni
Copy link
Contributor Author

@ljharb any idea why coverage dropped?

@ljharb

This comment has been minimized.

@lencioni

This comment has been minimized.

When modifiers need to be rebuilt, which happens pretty frequently, we
iterate over every day and create a new moment instance for these
operations. These moment instances are never mutated, so we can safely
store and reuse them to improve performance.

This optimization reduces the time spent in
DayPickerRangeController#componentWillReceiveProps when selecting dates
from ~16ms to ~6-10ms.
@lencioni lencioni merged commit a60a76a into master May 31, 2019
@lencioni lencioni deleted the pooled-moment branch May 31, 2019 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance semver-patch: fixes/refactors/etc Anything that's not major or minor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants