From bf08aa29b834498542e86883b052933ebf66479f Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Tue, 8 Jan 2019 00:24:21 -0800 Subject: [PATCH] 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. --- common/common/segments.py | 4 +--- common/setup.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/common/common/segments.py b/common/common/segments.py index e03e20c..65b7e20 100644 --- a/common/common/segments.py +++ b/common/common/segments.py @@ -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), diff --git a/common/setup.py b/common/setup.py index 8c751ec..ae2a724 100644 --- a/common/setup.py +++ b/common/setup.py @@ -8,6 +8,5 @@ setup( "gevent", "monotonic", "prometheus-client", - "python-dateutil", ], )