From d7301dee5b2f454bb1efb0f3ce4c3ff6ee8d3b10 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 24 Sep 2026 14:36:27 +0200 Subject: [PATCH] perf(time): cache parsed relative time strings `value_of` parsed the same few relative time strings ("1 day", "28 days", ...) with a regex every time, although task definitions contain several of them and are resolved multiple times. Its results are timedeltas, which are immutable, so they are now cached. On a typical task definition, resolve_timestamps takes 16.4us instead of 20.5us. --- src/taskgraph/util/time.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/taskgraph/util/time.py b/src/taskgraph/util/time.py index a613f9e83..f2866f4f4 100644 --- a/src/taskgraph/util/time.py +++ b/src/taskgraph/util/time.py @@ -7,6 +7,7 @@ import datetime +import functools import re PATTERN = re.compile(r"((?:\d+)?\.?\d+) *([a-z]+)") @@ -57,6 +58,7 @@ class UnknownTimeMeasurement(Exception): pass +@functools.cache def value_of(input_str): """ Convert a string to a json date in the future