Commit 0187a79
authored
Improve the performance of
Improve the performnace of the calendar `until()` function.
- Tighten the estimation of the number of months between two dates in
order to reduce the number of incremental `surpasses()` tests. This is
done by introducing a new DateFieldsResolver function,
`min_months_from()`, which the Coptic, Ethiopic, and Hebrew calendar
implementations customize.
- Eliminate the `surpasses()` loop for the final days delta calculation.
Instead compute an intermediate date, which is the start date plus the
years, months, and weeks computed so far. Subtract the Rata Die of the
intermediate date from that of the target date to get the days field of
the DateDuration.
- Fix minor typos in function names and comments.
Performance, as measured using criterion, is improved for Years and
Months intervals. Improvements on the order of 20% to 80%, or 100s of ns
to >1 ms, are shown, for base times of 500 ns to 5 ms.
For Weeks and Days, which are already computed efficiently using RD
subtraction, criterion measures a slight slowdown (on the order of 1 ns,
for a 15-20 ns operation). This is most likely due to a change in
compiler inlining, optimization, register usage, etc., since the code
for Days/Weeks has not changed.
<!--
Thank you for your pull request to ICU4X!
Reminder: try to use [Conventional
Comments](https://conventionalcomments.org/) to make comments clearer.
Please see
https://github.com/unicode-org/icu4x/blob/main/CONTRIBUTING.md for
general
information on contributing to ICU4X.
-->ArithmeticDate.until() (#7739)1 parent 6cb032d commit 0187a79
File tree
8 files changed
+49
-12
lines changed- components/calendar
- benches
- src
- cal
8 files changed
+49
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
590 | 597 | | |
591 | 598 | | |
592 | 599 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
137 | 143 | | |
138 | 144 | | |
139 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
238 | 246 | | |
239 | 247 | | |
240 | 248 | | |
| |||
902 | 910 | | |
903 | 911 | | |
904 | 912 | | |
905 | | - | |
| 913 | + | |
906 | 914 | | |
907 | 915 | | |
908 | 916 | | |
| |||
992 | 1000 | | |
993 | 1001 | | |
994 | 1002 | | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
1003 | 1009 | | |
1004 | 1010 | | |
1005 | 1011 | | |
| |||
1038 | 1044 | | |
1039 | 1045 | | |
1040 | 1046 | | |
| 1047 | + | |
1041 | 1048 | | |
1042 | 1049 | | |
1043 | 1050 | | |
| |||
1057 | 1064 | | |
1058 | 1065 | | |
1059 | 1066 | | |
| 1067 | + | |
1060 | 1068 | | |
1061 | 1069 | | |
1062 | 1070 | | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
1063 | 1076 | | |
1064 | 1077 | | |
1065 | 1078 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| |||
0 commit comments