Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-68289

Avoid excessive allocations in timelib library

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • QE 2022-09-19, QE 2022-10-03

      Whenever a time object is manipulated, the associated timezone is queried for its offset from the UTC, using these patterns:

      void timelib_update_from_sse(timelib_time *tm)
      ...
      			gmt_offset = timelib_get_time_zone_info(tm->sse, tm->tz_info);
      			timelib_unixtime2gmt(tm, tm->sse + gmt_offset->offset);
      			timelib_time_offset_dtor(gmt_offset);
      
      static void do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi)
      ...
      			current = timelib_get_time_zone_info(tz->sse, tzi);
      			after = timelib_get_time_zone_info(tz->sse - current->offset, tzi);
      			tz->is_localtime = 1;
      
      			in_transition = (
      				((tz->sse - after->offset) >= (after->transition_time + (current->offset - after->offset))) &&
      				((tz->sse - after->offset) < after->transition_time)
      			);
      
      			if ((current->offset != after->offset) && !in_transition) {
      				adjustment = -after->offset;
      			} else {
      				adjustment = -current->offset;
      			}
      			timelib_time_offset_dtor(current);
      			timelib_time_offset_dtor(after);
      
      Seconds TimeZone::utcOffset(Date_t date) const {
          if (isTimeZoneIDZone()) {
              auto* offset = timelib_get_time_zone_info(
                  durationCount<Seconds>(date.toDurationSinceEpoch()), _tzInfo.get());
              auto timezoneOffsetFromUTC = Seconds(offset->offset);
              timelib_time_offset_dtor(offset);
      

      In these cases the caller is only interested in the offset from UTC, instead of the full set of information available from timelib_get_time_zone_info; using this API has the side effect of requiring the allocations and immediate deallocation of two memory buffers (for the returned struct and for the string representing the timezone name).
      The code could use a simpler API similar to timelib_get_current_offset (that accepts a full timelib_time rather than the time and the timezone) in order to return just the offset without the extra information

            Assignee:
            alberto.massari@mongodb.com Alberto Massari
            Reporter:
            alberto.massari@mongodb.com Alberto Massari
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: