-
-
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
Optimize toISODateString and toISOMonthString #1656
Conversation
There was a problem hiding this 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?
@ljharb I added a test for toISODateString but not toISOMonthString because the existing tests there were all written in this way. |
test/utils/toISOMonthString_spec.js
Outdated
@@ -1,9 +1,11 @@ | |||
import moment from 'moment'; | |||
import { expect } from 'chai'; | |||
|
|||
import { ISO_FORMAT, ISO_MONTH_FORMAT } from '../../src/constants'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
2d7fd47
to
f888d7d
Compare
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.
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](https://user-images.githubusercontent.com/195534/58646915-46cf5980-82bb-11e9-96e9-3e6a63b8824b.png)
After:
![image](https://user-images.githubusercontent.com/195534/58646931-4fc02b00-82bb-11e9-9c47-3fd2fed7cdd9.png)