Skip to content

Commit 200c33f

Browse files
committed
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
1 parent 5fb0641 commit 200c33f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/taskgraph/parameters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import gzip
66
import hashlib
7+
import inspect
78
import json
89
import os
910
import time
@@ -110,7 +111,7 @@ def _get_defaults(repo_root=None):
110111
"do_not_optimize": [],
111112
"enable_always_target": True,
112113
"existing_tasks": {},
113-
"files_changed": repo.get_changed_files("AM"),
114+
"files_changed": lambda: repo.get_changed_files("AM"),
114115
"filters": ["target_tasks_method"],
115116
"head_ref": repo.branch or repo.head_rev,
116117
"head_repository": repo_url,
@@ -210,7 +211,7 @@ def _fill_defaults(repo_root=None, **kwargs):
210211

211212
for name, default in defaults.items():
212213
if name not in kwargs:
213-
kwargs[name] = default
214+
kwargs[name] = default() if inspect.isfunction(default) else default
214215
return kwargs
215216

216217
def check(self):

0 commit comments

Comments
 (0)