Speed up variant handling on large variant matrices #6267
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #6267"
general
weight: 0.35
beckermr
This should really help rerendering things at conda forge.
Broken out into separate ideas in distinct commits. The biggest are the first two:
list_of_dicts_to_dict_of_listscopied every zipped key's growing list for every variant, which was quadratic in the number of variants; commit 1 accumulates in place, and commit 2 squishes a column at a time for a further constant-factor gain.Along with other speedups this should really help conda-forge with the growing number of global pinnings.
xref:
https://github.com/conda-forge/rattler-build-conda-compat/pull/146
https://github.com/conda-forge/conda-smithy/pull/2751
<details><summary>Claude</summary>
Description
Four commits, ordered from the smallest and most obviously safe to the larger ones. None changes a result. (An ASCII fast path for recipe file decoding, which does change how some unusual files are read, was split out into conda/conda-build#6270.)
1. Accumulate in place. For every variant, each key's collected values were rebuilt from scratch (
list(old) + [v], thenlist(set(...));set(old) | set(v)). Zipped keys keep one value per variant, duplicates included, because they are paired up again at the end, so their list grows to the number of variants and was copied in full for every variant, which is quadratic in the number of variants; the other keys only hold their few distinct values but were still rebuilt every time. Zipped keys now extend their list and every other key collects into a set, turned into a list at the end where its last value was a scalar, as before. opencv-feedstock: 204 s → 99 s.2. Squish a column at a time. The same O(variants × keys) work with a much smaller constant: when every variant holds the same keys, a column is
list(map(itemgetter(k), variants)); a column of hashable scalars is oneset()(or stays a list for zipped keys); any other column replays the original per-value rules in order, including the mixed scalar/list/dict cases and theAttributeErrora dict raises after a scalar. Scalars are recognised withisinstance, so subclasses ofstrsuch as ruamel.yaml'sScalarStringtake the one-step path too. opencv-feedstock: 99 s → 76 s; on a synthetic list of 16,000 variants of 520 keys the two are close (1.3 s against 1.4 s). This is the larger change; commit 1 alone removes the quadratic part. New tests pin the behaviour and pass onmaintoo; a 20,000-case random comparison against the old implementation matched for both commits, except for the order of values both collect through aset.3.
get_varsandfilter_by_key_valuecomparisons in C.get_varscompared each variable across every variant in a generator;any(map(ne, repeat(first[var]), map(itemgetter(var), others)))makes the same comparisons, same short circuit, sameKeyError(andoperator.nestill reflects aNotImplementedfrom mixed types; tested).filter_by_key_valuecalledget_logger()and formatted a debug f-string with the whole list of target values for every variant it dropped, althoughget_loggersets INFO; the messages are now built only when debug is enabled. opencv-feedstock: 76 s → 67 s.4. libyaml for variant config files.
parse_config_fileusesCBaseLoaderwhen PyYAML has libyaml: the same constructor and resolver, 3 ms instead of 20 ms for the global pinning, identical data for the pinning and every config and migration file of 23 feedstocks.Locally with conda 26.10,
tests/test_variants.py,test_utils.py,test_render.py,test_metadata.py: the same three tests fail here as onmainin this environment (test_build_bootstrap_env_by_name,test_build_run_exports_act_on_host,test_inner_python_loop_with_output: unsatisfiable win-64 test packages); everything else passes.Why rerenders are slow, and the series this PR is part of
conda-build explodes every multi-valued key of the combined variant spec into the variant matrix before it learns which keys a recipe uses. conda-smithy renders against the whole global pinning, which holds the keys of every feedstock, so keys like
nodejs,r_base,hip_compiler_version,blas_impland theroot_base,libarrowandgeant4/clhepzips multiply the matrix of recipes that never mention them. That matrix is then walked by code that is quadratic, or Python-level per entry. For opencv-feedstock, 20 builds become 28,800 variants of ~520 keys, and a rerender takes 3.5 minutes and 3.2 GB.!Where opencv's 28,800 variants come from
The fix is spread over three projects, one draft PR each. Inside each PR the commits are ordered from the most conservative (equivalent code, same result) to the least, and each commit stands alone:
| PR | commits, in order |
|----|-------------------|
| conda/conda-build#6267 | 1. values accumulated in place in
list_of_dicts_to_dict_of_lists· 2. the same function a column at a time · 3.get_vars/filter_by_key_valuecomparisons in C · 4. libyaml for variant configs || conda-forge/rattler-build-conda-compat#146 | 1. an output that uses no variables no longer explodes the whole pinning · 2. variants passed to rattler-build as JSON |
| conda-forge/conda-smithy#2751 | 1. lazy imports of the GitHub and lint modules · 2. collapse variant dimensions the recipe cannot use (the one change that rests on a rule rather than on equivalent code) |
!What each commit removes from a rerender
Median rerender wall time after each commit, in the order of the chart: main, then +1 … +4 for this PR's commits, +5 … +6 for rattler-build-conda-compat, +7 … +8 for conda-smithy (lazy imports, then the collapse). One run for the slow feedstocks, 3–5 for the fast ones; same pinning for all, against conda-build
mainas of 2026-11-17; the rendered feedstock is byte-identical to main's at every step. Steps that change a slow feedstock by a few seconds are within run-to-run noise.| feedstock | main | +1 | +2 | +3 | +4 | +5 | +6 | +7 | +8 |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| ffmpeg | 461 s | 161 s | 122 s | 106 s | 108 s | 106 s | 106 s | 105 s | 5.3 s |
| opencv | 204 s | 99 s | 76 s | 67 s | 61 s | 59 s | 59 s | 60 s | 12 s |
| boost | 106 s | 86 s | 78 s | 76 s | 78 s | 81 s | 75 s | 75 s | 16 s |
| python | 59 s | 48 s | 42 s | 40 s | 39 s | 40 s | 39 s | 38 s | 18 s |
| pytorch-cpu | 56 s | 27 s | 19 s | 20 s | 19 s | 18 s | 19 s | 19 s | 4.5 s |
| petsc | 22 s | 22 s | 22 s | 20 s | 21 s | 1.6 s | 1.5 s | 1.4 s | 1.4 s |
| r-ggplot2 | 7.0 s | 5.8 s | 4.7 s | 4.7 s | 4.6 s | 4.5 s | 4.5 s | 4.5 s | 1.5 s |
| h5netcdf | 1.1 s | 1.0 s | 1.1 s | 1.1 s | 1.0 s | 1.0 s | 1.0 s | 0.9 s | 0.8 s |
v1 recipes (petsc, h5netcdf) gain mostly from rattler-build-conda-compat 1; v0 recipes from this PR's first three commits and, for the large ones, the conda-smithy collapse.
One recipe this series does not fix: ctng-compilers (20 outputs, 51
pin_subpackage) took 8.4 minutes with an earlier version of this series; on main it was killed after 2 h 10 min at 164 GB of memory without finishing. Its time is in conda-build re-rendering outputs for eachpin_subpackage, not in the variant matrix.<sub>Measured on one Linux machine (24 cores, each rerender single-threaded), rattler-build 0.76.1, pinning of 2026-11-17. Feedstocks that fail to rerender on main itself (cupy, gdal, h5py, numpy, scipy:
variant_addon their in-flight python 3.14t/3.15 migrations) are left out.</sub>Checklist - did you ...
newsdirectory (using the template) for the next release's release notes?Resume this Claude session:
</details>