[SERVER-68014] Eliminate the 70% performance regression when passing "UTC" to $dateTrunc Created: 13/Jul/22 Updated: 29/Oct/23 Resolved: 02/Aug/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 6.1.0-rc0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Nikita Lapkov (Inactive) | Assignee: | Alberto Massari |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Sprint: | QE 2022-08-08 |
| Participants: |
| Description |
|
Let us consider running the following query over the collection of 1100000 documents with just one field "a", which has a date value:
Note that since we did not pass the timezone parameter, $dateTrunc will default to UTC. This query runs at 1.53 sec / op. But if we pass timezone parameter as a string "UTC" (same semantics, just passing the default parameter explicitly), the query runs at 2.58 sec / op, which is 69% slower. A combination of the following behavior causes the regression:
Later on repeatedly during runtime, the following code path is exercised:
If the timezone is constructed using mongo::TimeZoneDatabase::utcZone() (which is the case for the absent timezone parameter for $dateTrunc), TIMELIB_ZONETYPE_ID is not set and no additional allocations are performed. During our investigation, we have noticed as much as 2x performance regression because of these allocations when executing $dateTrunc in our time-series prototype for SBE. While the frequency of timezone parsing is reduced by the proposed change in There might be possibilities to also optimize for timezones other than UTC but attention must be paid with regard to DST. UTC has no DST concept (permanent offset == 0) so it does not need to be looked up again when the time value passed into the expression changes. |
| Comments |
| Comment by Githook User [ 02/Aug/22 ] |
|
Author: {'name': 'Alberto Massari', 'email': 'alberto.massari@mongodb.com', 'username': 'albymassari'}Message: |
| Comment by Ana Meza [ 19/Jul/22 ] |
|
rushan.chen@mongodb.com assigning you to find an assignee |