rea-analysis-optimization
MOmorluto/rea485k近 7 天新增 9,215 个 star
Make gflow-cli's tests and CI fast without weakening them: measure the wall clock, find what dominates it, and apply the lever that fits the scenario (cut a per-test cost, -n workers, shards, rebalancing, profile clones for live e2e, cancelling superseded runs). Targets: CI in 3-5 minutes, the local offline suite in 3 minutes, live e2e as close to the slowest single generation as parallelism allows.
/gflow:optimize [ci | local | e2e] — test and CI speedgflow reverse-engineers a black box, so its quality rests on running tests often: the offline suite on every commit and the live e2e suite on every change to a Flow surface. A slow loop is a quality problem, because slow tests get run less. This skill is how speed work is done here.
Targets (owner rules):
A speed change never skips, deselects, xfails or marks a test slow to get it out of the run;
never loosens or deletes an assertion or shrinks a test's data; never raises a timeout to hide a
wait. Every test that ran before still runs, and still checks the same thing.
What is allowed and expected here, unlike in a generic speed rule: adding workers (-n),
adding shards, rebalancing shards, and cloning profiles for e2e. gflow's e2e time is mostly
model latency we cannot remove, so running tests concurrently is the main lever, not a dodge.
When a single test is itself slow, cut its cost first; parallelism hides a cost, it does not
remove it.
--durations alone (it
cannot tell setup from a wait from code under test).
gh run list --workflow CI --json databaseId,createdAt,updatedAt,event -L 20 for wall
time per run; gh run view <id> --json jobs for each job's start and end. Separate queue
time (waiting for a runner) from run time.--junitxml=<dir>/report.xml, then rank files by share of their
worker: python -m scripts.ci.pytest_speed rank <dir> --root . (config:
pytest-speed.toml).| Lever | Use when | How, here | Watch |
|---|---|---|---|
| Cancel superseded runs | Develop pushes queue behind each other | concurrency: in .github/workflows/ci.yml (in place; never cancel on main) | A burst of merges still queues; merge in sequence |
| Remove duplicate jobs | Two jobs run the same tests | Compare job test lists; fold, keep one source of coverage | Required-check names in branch protection |
Workers (-n) | One process is CPU- or wait-bound and tests are independent | -n auto --dist worksteal in CI; -n 8 --dist worksteal locally | A test that passes alone but fails under -n shares state: fix the state, never serialise it away |
Rebalance (--dist, shard split) | One worker or shard finishes far later than the rest | worksteal for tail; refresh tests/test_durations.json so scripts/ci/shard_tests.py splits whole files by measured time | Only when the measured tail is past run-to-run noise in 2 of 3 runs |
| Shards (CI matrix) | A balanced shard still exceeds ~2 min | Change every value in test-313-shard.matrix.shard to the new N (1/3, 2/3, 3/3 becomes 1/4 … 4/4; GFLOW_TEST_SHARD=k/N), never append one: mixed denominators make files run twice or not at all. The count floor is checked over the sum in test-313 | Runner start-up (~20-30 s) is paid per shard; past ~4-5 shards it stops paying |
| Cut a per-test cost | A file or test is slow against its baseline | pytest-speed: fixture timer (-p scripts.ci.pytest_speed.fixture_timer), first-cost, then remove the cost (share an expensive fixture at module scope, drop a fixed sleep for an awaited condition, fake a network call) | Shared fixtures must not leak state between tests |
| Serial tail | A job that runs after the tests dominates (SonarCloud needs combined coverage) | Start what can start earlier; keep the merge-coverage step small | Sonar's gate must still see all coverage |
| Profile clones (live e2e) | e2e runs one test at a time because one Chrome profile cannot be shared (exit 11) | One copy of a signed-in profile per xdist worker (the lock is keyed by directory), caches left out (~265 MB, ~4 s each); -n = number of clones. Measured working at 2 browsers per account (spike below). Prerequisite not built yet: the e2e fixtures read one GFLOW_CLI_E2E_PROFILE, so every xdist worker would open the same directory and the extras fail with exit 11; first add a worker→profile mapping (e.g. GFLOW_CLI_E2E_PROFILES=a,b,c indexed by PYTEST_XDIST_WORKER) | Wider fan-out is not measured yet; daily image quota and credits are per account; WAF throttling |
| Exclusive resources (e2e) | Two tests need the same project, quota or port | @pytest.mark.xdist_group("<resource>") and --dist loadgroup for that run (worksteal ignores groups) | Group only what truly conflicts, or the run goes serial again |
| Cut overhead around a generation (e2e) | A generating test spends much more than the model's own time | Fixture timer on one e2e file: browser launch, page load, fixed waits; reuse a warm page only where tests do not depend on fresh state | Never reuse state a test asserts on |
ci: measure the last 20 runs (step 1). Order of levers: cancel superseded runs → remove
duplicates → rebalance shards → add a shard → serial tail → per-test cost.local: -n 8 --dist worksteal; then rank and cut per-test costs. The full suite OOMs on
small machines: cap -n.e2e: e2e runs only on a machine with live profiles (GFLOW_CLI_E2E_PROFILE), never in
CI. Order: profile clones + -n → exclusive-resource groups → cut overhead around each
generation. Join the agent registry and lease browser-session first
(~/.agents/skills/multi-agent-dev); the A/B tool takes --lease-cmd / --release-cmd.
Spend credits only under the standing e2e grant, and say what was spent.The profile lock (profile_lease.py) is keyed by the profile directory, so a copy of a
signed-in profile has its own lock. Measured on 2026-11-12
(spike,
scripts/dev/spike_profile_clone_concurrency.py): one clone of denon82 drove flow.google.com
at the same time as the original, and both stayed signed in. Before relying on a wide fan-out
(4-12 workers), measure it the same way: Google throttling, the shared daily image quota and the
shared credit balance are per account, not per clone.
/gflow:optimize [ci|local|e2e] (thin wrapper around this file).$gflow:optimize. Cursor / Aider / agy: include this file in context.plan.MOmorluto/rea485k近 7 天新增 9,215 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star