Closed
Bug 978571
Opened 12 years ago
Closed 2 years ago
Performance issues with tests that involve timezones and recurrence
Categories
(Calendar :: ICAL.js Integration, defect)
Tracking
(Not tracked)
RESOLVED
INCOMPLETE
People
(Reporter: Fallen, Unassigned)
References
Details
(Keywords: perf)
Some tests take considerably longer with ical.js enabled. Last time I checked, this drills down to something within recurrence calculation.
The code for recurrence calculation was optimized at some point, so it might be a good idea to revert to the original 1:1 translation between libical and ical.js and see if the problem persists. Note however, there were a few oversights in the original translation, please check the git history of ical.js.
with libical:
test_alarm.js | test passed (time: 755.477ms)
test_alarmservice.js | test passed (time: 934.985ms)
test_datetime.js | test passed (time: 691.958ms)
test_items.js | test passed (time: 733.659ms)
test_providers.js | test passed (time: 1834.887ms)
test_recur.js | test passed (time: 660.349ms)
test_calmgr.js | test passed (time: 831.060ms)
test_deleted_items.js | test passed (time: 1130.018ms)
with ical.js:
test_alarm.js | test passed (time: 8391.704ms)
test_alarmservice.js | test passed (time: 17788.347ms)
test_datetime.js | test passed (time: 10346.354ms)
test_items.js | test passed (time: 10057.479ms)
test_providers.js | test passed (time: 3060.643ms)
test_recur.js | test passed (time: 1869.634ms)
test_calmgr.js | test passed (time: 9772.389ms)
test_deleted_items.js | test passed (time: 9527.612ms)
For all other tests, the extra time is within 100-200ms which I think is acceptable.
| Reporter | ||
Comment 1•12 years ago
|
||
Ok, I ran through this and the sad truth is, our code is correct. The problem is that recurrence calculation runs significantly slower than in C++.
Calculating all timezone changes between 1970 and 2019 for Europe/Berlin takes 5ms with libical and 30ms with ical.js. While this alone isn't that bad, the tests that are taking so long are doing timezone guessing. Checking /etc/timezone and friends doesn't bring an exact match, so all timezones are enumerated to find the best match. IIRC this was about 80ms per timezone, which adds up.
The only way we can improve speed is to rewrite the timezone parser, or at least add some performance optimizations.
I asked around at calconnect on other recurrence parser algorithms. One implementation I found quite interesting: Instead of taking the first occurrence and iterating through the years, you take the timeframe you want to expand occurrences in and apply each RRULE component. First you take FREQ/INTERVAL and create instances throughout the timeframe. Then for the BYxxx parts, If its an expanding BY-part, the previously found instances are expanded, if its a contracting BY-part, they are filtered. I don't yet know if this is faster since it might require a lot of iterating, but turning the problem around this way might bring some better results. One advantage is that there are less special cases to consider and its easier to support the full set of recurrence rules.
Another implementation I found is here <https://github.com/jkbr/rrule> but it took about the same time as ical.js.
I need to finish up some other things first, but I think rewriting the parser is worth a shot. There are two things we could try to speed up the code even more. First of all, instead of using ICAL.Time instances to do the calculation, we could use long values that encode an instance. Calculations on these values should be faster since its just number manipulation.
The second thing we can do, and this might be a little more challenging, is to use the asm.js subset. This will improve speed notably, but the code will become far more unreadable. It might even be easier to write the code in C and use emscripten to compile that to asm.js.
Comment 3•12 years ago
|
||
My first thought is, why do we have to guess the timezone for every occurrence?
Normally all recurrences of a given parent Item should have the same timezone. If this is correct, the timezone must only be guessed for the parent and then applied to every occurrence.
The only changes in time should be related to DST.
Is it possible to calculate the changes only in a specific range?
e.g. the change from/to DST occurs in March/April & Oct/Nov only as far as I could find out.
Or for the given Timezone the Changeover dates could be put into a variable and used from there.
Flags: needinfo?(Mozilla)
| Reporter | ||
Comment 4•12 years ago
|
||
We only have to guess the timezone once at startup, but this goes through every timezone in certain cases and expands it to some point in the future as defined by libical/ical.js. Timezones used within the app will have to be recalculated even after the initial guessing. In any case, once the changeover dates have been calculated it doesn't have to be repeated because its cached in memory.
The changes are already being calculated within a certain timeframe: between the DTSTART of the timezone, the requested date the timezone is set on, plus a few years extra. The only thing we can do is trim down the changes being calculated in the past. This is the same kind of optimization James and I had initially planned, fast forwarding calculations for certain rules.
What we can do is not only store the changeover dates in memory but also cache them on disk. Occurrence calculations with the same start date and recurrence pattern can be re-used. James already made preparations for this by making the state of the ical.js recurrence iterator persistable.
I'm still banging my head against this at times, hoping to see the matrix at some point and find a very smart mathematical algorithm that could make calculations very fast. If I do find something I will definitely make this part of my Master Project or Thesis :)
Comment 5•11 years ago
|
||
I just did a very unscientific test and got these numbers:
> icaljs libical
> test_rfc3339_parser.js 3598 299 12.0x
> test_recur.js 1717 560 3.1x
> test_alarm.js 490 191 2.6x
> test_ics.js 416 175 2.4x
> test_datetime.js 307 151 2.0x
> test_alarmservice.js 911 473 1.9x
> test_bug343792.js 243 147 1.7x
Comment 6•11 years ago
|
||
profiler tool https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Reporting_a_Thunderbird_Performance_Problem_with_G
note - the profiler version that works for Thunderbird in the above link is old (a year old?). Much improvement has occurred in the past year, so if the old version is not sufficient for the task, then we may need bug 1106414 and it's blocker bug 1100644. And for anyone trying linux see bug 838323
Comment 7•8 years ago
|
||
At the moment there is nothing I can contribute to this topic, so unassigning.
Status: ASSIGNED → NEW
Comment 8•8 years ago
|
||
If timezone guessing is the/a culprit here, we simply can replace that with what we get from the dateformst detection of JS, which takes 3-4 ms here to rsolve when putting it into the error console:
new Services.intl.DateTimeFormat().resolvedOptions().timeZone;
Updated•8 years ago
|
Assignee: Mozilla → nobody
| Reporter | ||
Comment 9•8 years ago
|
||
I'm sure we can get the timezone faster, the slow tests don't run in production code anyway. I am just concerned that using ical.js has a notable performance toll in general. If it is good enough for a large calendar, we can just ignore this and keep on improving.
Comment 10•4 years ago
|
||
In the process of migrating remaining bugs to the new severity system, the severity for this bug cannot be automatically determined. Please retriage this bug using the new severity system.
Severity: major → --
Comment 11•2 years ago
|
||
Will bug 1789999 have resolved this?
Flags: needinfo?(philipp)
Flags: needinfo?(geoff)
| Reporter | ||
Comment 12•2 years ago
|
||
This is good historical knowledge, but I don't think there is anything actionable here. We should continue to look for performance improvements, but ical.js is not going away any time soon.
Status: NEW → RESOLVED
Closed: 2 years ago
Flags: needinfo?(philipp)
Flags: needinfo?(geoff)
Resolution: --- → INCOMPLETE
You need to log in
before you can comment on or make changes to this bug.
Description
•