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

Optimize toISODateString and toISOMonthString #1656

Merged
merged 1 commit into from
May 30, 2019
Merged

Optimize toISODateString and toISOMonthString #1656

merged 1 commit into from
May 30, 2019

Conversation

lencioni
Copy link
Contributor

These functions get called repeatedly when computing modifiers, which
happens any time components like DayPickerRangeController receives
props.

By manually building this string instead of relying on moment's format
function, we can get better performance. In my profiling, this cuts the
time spent in DayPickerRangeController#componentWillReceiveProps from
~50ms to ~40ms.

Before:
image

After:
image

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

coveralls commented May 30, 2019

Coverage Status

Coverage remained the same at 84.494% when pulling 9f54116 on iso-format into 4073d24 on master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests comparing the output of this function to the moment format method directly, to ensure there’s no drift?

@lencioni
Copy link
Contributor Author

@ljharb I added a test for toISODateString but not toISOMonthString because the existing tests there were all written in this way.

@@ -1,9 +1,11 @@
import moment from 'moment';
import { expect } from 'chai';

import { ISO_FORMAT, ISO_MONTH_FORMAT } from '../../src/constants';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why inline this, if the constant is still going to exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only used in one test file now, and in no production code, so I don't think it makes sense to ship this code to clients.

Copy link
Member

@ljharb ljharb May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure but this PR doesn’t delete the constant (which would be a breaking change). Can the inlining wait til then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot to save that file. Yeah, I can keep it for now. I'll add a note to delete it as part of the next breaking change.

@lencioni lencioni force-pushed the iso-format branch 2 times, most recently from 2d7fd47 to f888d7d Compare May 30, 2019 16:56
These functions get called repeatedly when computing modifiers, which
happens any time components like DayPickerRangeController receives
props.

By manually building this string instead of relying on moment's format
function, we can get better performance. In my profiling, this cuts the
time spent in DayPickerRangeController#componentWillReceiveProps from
~50ms to ~40ms.
@lencioni lencioni merged commit 9f54116 into master May 30, 2019
@majapw majapw deleted the iso-format branch May 30, 2019 17:24
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