turbo-tasks-backend benches: skip keyed_deps setup for benchmarks excluded by the filter (#101933)
### What?
The `keyed_deps` benchmark in `turbo-tasks-backend` now skips its
untimed per-configuration work for benchmarks the Criterion name filter
doesn't select. That work covers:
- the tokio runtime,
- the `KEYED_DEPS_MEM` memory measurement,
- the optional `KEYED_DEPS_PERSIST` measurement,
- building the graph for the `change_*` scenarios.
So `cargo bench -p turbo-tasks-backend --bench mod -- <other group>` no
longer runs any `keyed_deps` work and no longer prints any
`KEYED_DEPS_*` lines.
### Why?
Before this change, that setup ran in the bench function body, outside
the `bench_function` closures. Criterion's filter only skips the
closures, so the full grid ran for every filter. The grid is up to 120
configurations, including n=1000/m=10000. Filtering for another group
(e.g. `priority_contention`) made the run much slower: about 160 s in
total versus about 37 s of measured work. It also inflated the
process-level peak RSS, which other benches' fixed-work memory
measurements rely on.
### How?
- The setup now runs lazily inside the `bench_function` closures, so
Criterion's own filter decides whether it runs. This also covers regex
and `--exact` filters, `--list`, and `--test`, without re-parsing the
command line.
- A small per-configuration state holds the runtime in a `OnceCell`. The
first selected benchmark of a configuration creates it and runs the
memory (and persistence) measurement, so that still happens once per
configuration, outside the timed region.
- The `change_*` graph is built on the first call of its closure and
kept for later calls. The rerun report and the backend shutdown only run
if the graph was built.
- `KEYED_DEPS_MEMORY_ONLY` is an explicit opt-in, so it still forces the
measurement. The `KEYED_DEPS_PROFILE` driver is unchanged.
### Verification
- `cargo bench -p turbo-tasks-backend --bench mod --no-run`, `cargo
fmt`, `cargo clippy -p turbo-tasks-backend --benches`
- `--bench no_such_bench` and `--test --exact task_overhead/direct/1`
with the default grid: no `KEYED_DEPS_*` output (about 8 ms instead of
the full grid)
- `--list keyed_deps`: no setup work
- Small grids filtered by regex (`keyed_deps/(initial|change_one)/...`)
and by exact ID (`change_unread/...`): one `KEYED_DEPS_MEM` line per
selected configuration, `KEYED_DEPS_RERUN` with the expected rerun
counts (1 for `change_one` disjoint, 0 for `change_unread`)
- `KEYED_DEPS_MEMORY_ONLY=1` with a non-matching filter still prints
`KEYED_DEPS_MEM`
- Not run: the `priority_contention` example with
`PRIORITY_CONTENTION_FIXED_WORK=realistic_warm/32x2048`. The same
filtering behavior was checked with the filters above.
<!-- NEXT_JS_LLM -->
<!-- fleet 23be4c06-9b98-4145-b2a9-e7965a62e03e -->
Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>