parse_segment_path: Use datetime.strptime instead of dateutil.parser

strptime is much faster but can't handle as varied formats.
But in this case we fully control the format, so there's no reason not to use it.

Profiling suggests we spend about 80% of our time in get_best_segments just parsing dates,
so this is a signifigant performance gain.
pull/35/head
Mike Lang 6 years ago committed by Mike Lang
parent bcdb268ce8
commit bf08aa29b8

@ -11,8 +11,6 @@ import os
import sys
from collections import namedtuple
import dateutil.parser
from .stats import timed
@ -58,7 +56,7 @@ def parse_segment_path(path):
path = path,
stream = stream,
variant = variant,
start = dateutil.parser.parse("{}:{}".format(hour, time)),
start = datetime.datetime.strptime("{}:{}".format(hour, time), "%Y-%m-%dT%H:%M:%S.%f"),
duration = datetime.timedelta(seconds=float(duration)),
is_partial = type == "partial",
hash = unpadded_b64_decode(hash),

@ -8,6 +8,5 @@ setup(
"gevent",
"monotonic",
"prometheus-client",
"python-dateutil",
],
)

Loading…
Cancel
Save