improvement: to_offset avoids binary search if the timestamp is greatr than the biggest one #105
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The subsequent optimization of #103
The logic inside of
Tzif#to_offset
binary_search_by_key find the index from transitions, when the timestamp is greater than all timestamp in transitions. It's not needed to binary search.
It always happens when some timezones had DST before, but DST is canceled for now.
Change
Compare the timestamp with the biggest timestamp in
transitions
. Iftimestamp > self.transitions.last().unwrap().timestamp
, we can avoid the binary search.Performance change
In biref, the performance of
instant_to_civil_datetime_static-Asia/Shanghai
is improved 2 times via cthe urrent PR and #104The performance of
instant_to_civil_datetime_static-Asia/Shanghai
:99.3±1.35ns
: Without current PR and improvement: ReasonablePosixTimeZone#to_offset returns default value directly when dst is none #10468.4±5.85ns
: master with improvement: ReasonablePosixTimeZone#to_offset returns default value directly when dst is none #10450.1±1.02ns
: With current PR and improvement: ReasonablePosixTimeZone#to_offset returns default value directly when dst is none #104