Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up rendering by avoiding costly/redundant function calls #5248

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ def select_lines(data, namespace, variants_in_place):
if line.lstrip().startswith("#"):
# Don't bother with comment only lines
continue
m = sel_pat.match(line)
if m:
# Checking for "[" and "]" before regex matching every line is a bit faster.
if "[" in line and "]" in line and (m := sel_pat.match(line)):
cond = m.group(3)
try:
if eval_selector(cond, namespace, variants_in_place):
Expand Down Expand Up @@ -889,8 +889,8 @@ def get_output_dicts_from_metadata(metadata, outputs=None):
outputs.append(OrderedDict(name=metadata.name()))
for out in outputs:
if (
"package:" in metadata.get_recipe_text()
and out.get("name") == metadata.name()
out.get("name") == metadata.name()
and "package:" in metadata.get_recipe_text()
):
combine_top_level_metadata_with_output(metadata, out)
return outputs
Expand Down Expand Up @@ -1015,6 +1015,7 @@ def get_updated_output_dict_from_reparsed_metadata(original_dict, new_outputs):
return output_d


@lru_cache(maxsize=200)
def _filter_recipe_text(text, extract_pattern=None):
if extract_pattern:
match = re.search(extract_pattern, text, flags=re.MULTILINE | re.DOTALL)
Expand Down Expand Up @@ -1665,7 +1666,6 @@ def build_id(self):
raise RuntimeError(
f"Couldn't extract raw recipe text for {self.name()} output"
)
raw_recipe_text = self.extract_package_and_build_text()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how much of a speedup removing this gives us (since both of us did this)

raw_manual_build_string = re.search(r"\s*string:", raw_recipe_text)
# user setting their own build string. Don't modify it.
if manual_build_string and not (
Expand Down Expand Up @@ -2641,13 +2641,11 @@ def get_loop_vars(self):
return variants.get_vars(_variants, loop_only=True)

def get_used_loop_vars(self, force_top_level=False, force_global=False):
return {
var
for var in self.get_used_vars(
force_top_level=force_top_level, force_global=force_global
)
if var in self.get_loop_vars()
}
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)

def get_rendered_recipe_text(
self, permit_undefined_jinja=False, extract_pattern=None
Expand Down
24 changes: 15 additions & 9 deletions conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,16 +697,18 @@ def get_package_variants(recipedir_or_metadata, config=None, variants=None):
def get_vars(variants, loop_only=False):
"""For purposes of naming/identifying, provide a way of identifying which variables contribute
to the matrix dimensionality"""
special_keys = {"pin_run_as_build", "zip_keys", "ignore_version"}
special_keys.update(set(ensure_list(variants[0].get("extend_keys"))))
first_variant, *other_variants = variants
special_keys = {
"pin_run_as_build",
"zip_keys",
"ignore_version",
*ensure_list(first_variant.get("extend_keys")),
}
loop_vars = [
k
for k in variants[0]
for k, v in first_variant.items()
if k not in special_keys
and (
not loop_only
or any(variant[k] != variants[0][k] for variant in variants[1:])
)
and (not loop_only or any(variant[k] != v for variant in other_variants))
]
return loop_vars

Expand Down Expand Up @@ -763,7 +765,9 @@ def find_used_variables_in_shell_script(variant, file_path):
text = f.read()
used_variables = set()
for v in variant:
variant_regex = r"(^[^$]*?\$\{?\s*%s\s*[\s|\}])" % v
if v not in text:
continue
variant_regex = rf"(^[^$]*?\$\{{?\s*{re.escape(v)}\s*[\s|\}}])"
if re.search(variant_regex, text, flags=re.MULTILINE | re.DOTALL):
used_variables.add(v)
return used_variables
Expand All @@ -774,7 +778,9 @@ def find_used_variables_in_batch_script(variant, file_path):
text = f.read()
used_variables = set()
for v in variant:
variant_regex = r"\%" + v + r"\%"
if v not in text:
continue
variant_regex = rf"\%{re.escape(v)}\%"
if re.search(variant_regex, text, flags=re.MULTILINE | re.DOTALL):
used_variables.add(v)
return used_variables
19 changes: 19 additions & 0 deletions news/5248-render-speedups-func-calls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Speed up rendering by avoiding costly/redundant function calls. (#5248)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
Comment on lines +1 to +19
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm impartial on whether we should or should not include this news entry (meaning, I don't necessarily consider this a "significant" change).
We can include it if we want to track such changes more obviously or exclude it to reduce noise in the changelog 🤷 .

Loading