perf(py_wheel): defer depset expansion to execution time by bd-dstodolsky · Pull Request #3599 · bazel-contrib/rules_python
Replace analysis-time depset.to_list() loop with Args.add_all(map_each=...) and ctx.actions.write(Args), deferring depset expansion to execution time. The old code built the input file list via string concatenation in a loop, which is O(n^2) in the total string length. For large py_wheel targets this dominated analysis time (~18s for ~18k transitive files in a production monorepo). Tested under Bazel 8.5.1 and 9.0.0. Add tests/py_wheel_performance/ with: - A correctness test verifying wheel contents (100 deps) - A scaling regression test (tagged manual) asserting analysis time grows linearly, not quadratically, with dep count (5k vs 10k deps) Scaling test results (5k vs 10k deps, best of 3): Before: 2825 ms / 8616 ms = 3.05x (quadratic) After: 502 ms / 776 ms = 1.55x (linear)