Skip to content

Slow date parsing #10942

@bep

Description

@bep

I'm investigating some performance degradation in some work I'm doing, and see time parsing (unrelated to the work I'm doing) light up as a christmas tree in the memory profiler:

flat  flat%   sum%        cum   cum%
2097170 13.54% 13.54%    2097170 13.54%  time.cloneString (inline)
1409116  9.10% 22.64%    3506286 22.64%  time.newParseError

I guess this comes from the ineffective way of guessing the format in the upstream cast library:

func parseDateWith(s string, location *time.Location, formats []timeFormat) (d time.Time, e error) {

	for _, format := range formats {
		if d, e = time.Parse(format.format, s); e == nil {

			// Some time formats have a zone name, but no offset, so it gets
			// put in that zone name (not the default one passed in to us), but
			// without that zone's offset. So set the location manually.
			if format.typ <= timeFormatNamedTimezone {
				if location == nil {
					location = time.Local
				}
				year, month, day := d.Date()
				hour, min, sec := d.Clock()
				d = time.Date(year, month, day, hour, min, sec, d.Nanosecond(), location)
			}

			return
		}
	}
	return d, fmt.Errorf("unable to parse date: %s", s)
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions