Skip to content

Commit

Permalink
perf: pass used_vars subset to get_loop_vars
Browse files Browse the repository at this point in the history
rather than computing all loop vars and then intersecting,
only consider relevant keys when computing loop vars

reduces get_used_loop_vars from O(n_vars * n_variants) to O(n_used_vars * n_variants)
  • Loading branch information
minrk committed Jul 1, 2024
1 parent 0797c42 commit f287604
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2778,15 +2778,16 @@ def get_output_metadata_set(
_check_run_constrained(output_tuples)
return output_tuples

def get_loop_vars(self):
return get_vars(getattr(self.config, "input_variants", self.config.variants))
def get_loop_vars(self, subset=None):
return get_vars(
getattr(self.config, "input_variants", self.config.variants), subset=subset
)

def get_used_loop_vars(self, force_top_level=False, force_global=False):
loop_vars = self.get_loop_vars()
used_vars = self.get_used_vars(
force_top_level=force_top_level, force_global=force_global
)
return set(loop_vars).intersection(used_vars)
return self.get_loop_vars(subset=used_vars)

def get_rendered_recipe_text(
self, permit_undefined_jinja=False, extract_pattern=None
Expand Down
13 changes: 9 additions & 4 deletions conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,10 @@ def get_package_variants(recipedir_or_metadata, config=None, variants=None):
return filter_combined_spec_to_used_keys(combined_spec, specs=specs)


def get_vars(variants: Iterable[dict[str, Any]]) -> set[str]:
def get_vars(
variants: Iterable[dict[str, Any]],
subset: set[str] | None = None,
) -> set[str]:
"""For purposes of naming/identifying, provide a way of identifying which variables contribute
to the matrix dimensionality"""
first, *others = variants
Expand All @@ -710,10 +713,12 @@ def get_vars(variants: Iterable[dict[str, Any]]) -> set[str]:
"ignore_version",
*ensure_list(first.get("extend_keys")),
}
to_consider = set(first)
if subset:
to_consider.intersection_update(subset)
to_consider.difference_update(special_keys)
return {
var
for var in set(first) - special_keys
if any(first[var] != other[var] for other in others)
var for var in to_consider if any(first[var] != other[var] for other in others)
}


Expand Down

0 comments on commit f287604

Please sign in to comment.