From 200c33fbbb2cbe3387a107a37a9960d3ae83aa5b Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 9 Jan 2025 15:28:26 +0900 Subject: [PATCH] Avoid computing expensive default values when the value is overridden anyways The most expensive call at the moment is repo.get_changed_files, which does down the drain if: - another default_fn overrides the value - an explicit override is given when creating the `Parameters` With this change, the default function can return a function as a value, which is not evaluated unless necessary. Fixes #616 --- src/taskgraph/parameters.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/taskgraph/parameters.py b/src/taskgraph/parameters.py index 886db3f21..223831bee 100644 --- a/src/taskgraph/parameters.py +++ b/src/taskgraph/parameters.py @@ -4,6 +4,7 @@ import gzip import hashlib +import inspect import json import os import time @@ -110,7 +111,7 @@ def _get_defaults(repo_root=None): "do_not_optimize": [], "enable_always_target": True, "existing_tasks": {}, - "files_changed": repo.get_changed_files("AM"), + "files_changed": lambda: repo.get_changed_files("AM"), "filters": ["target_tasks_method"], "head_ref": repo.branch or repo.head_rev, "head_repository": repo_url, @@ -210,7 +211,7 @@ def _fill_defaults(repo_root=None, **kwargs): for name, default in defaults.items(): if name not in kwargs: - kwargs[name] = default + kwargs[name] = default() if inspect.isfunction(default) else default return kwargs def check(self):