agentleFS
bInference-LabbInference-Lab/bInference/.agents/skills/speed-up-tests/SKILL.md

speed-up-tests

Skill2 starsChanged 2 days agoMITView on GitHub

Finds why a test file or a suite is slow or heavy on memory and fixes the cause, with numbers before and after. Use when a test command runs past a minute, a worker runs out of memory, or the CI test step grows.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run the slow file alone, with one worker, so the numbers belong to it:

    line 13
  2. Very specific:

    Memory grows run after run: keep a heap snapshot before you call it a leak.

    line 41
  3. Distinctive:

    Keep the coverage: if a slow end-to-end test goes, the behavior it proved needs a faster test at a lower layer in the same change.

    line 48
  4. Distinctive:

    Never fix speed with a higher timeout, fewer assertions, a skipped test or a retry.

    line 50
  5. Very specific:

    Never move a package to the isolated project to hide state a test leaves behind.

    line 51
  6. Very specific:

    Run the same command as in step 1, on the same machine, twice.

    line 56

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Speed up the tests

Measure first, change one thing, measure again with the same command. A guess about runner settings is not a fix.

1. Measure

Run the slow file alone, with one worker, so the numbers belong to it:

/usr/bin/time -l pnpm vitest run <file> --maxWorkers=1 --reporter=verbose
/usr/bin/time -l pnpm vitest run <file> --maxWorkers=1 --logHeapUsage

On Linux use /usr/bin/time -v. Write down the wall time, Vitest's own duration (tests, imports, setup), the maximum resident memory and the user and system CPU time. Run it twice and keep the second numbers, so a cold cache does not count.

For a whole package, run its folder the same way and sort the verbose output by duration.

2. Find the cause

Compare where the time goes:

  • Import time is large: the test pulls in a heavy module graph. Look for an import of a package root when one subpath would do, or a test that builds the whole composition root when a use case and its fakes would prove the same thing.
  • Setup time is large: a beforeEach that opens a store, starts a worker or a server, or builds the engine for each test. Build it once per file when the tests do not change it, and reset only the state they do change.
  • One test is slow: it waits. A test that waits on real time is broken: use the fake Clock and advance it. A property test with many runs: lower numRuns only when the property still covers its edges.
  • A worker or a child process stays open: the file ends late or the run hangs. Close every worker, server, client and database a test opens, in an afterEach or onTestFinished.
  • Memory grows run after run: keep a heap snapshot before you call it a leak. A module graph kept alive by isolate: false is not a leak; a store, timer or listener kept across tests is.

3. Fix it

  • Change the test or its fixture, not the code under test, unless the code itself is slow for users too.
  • Keep the coverage: if a slow end-to-end test goes, the behavior it proved needs a faster test at a lower layer in the same change. Say what coverage moved.
  • Never fix speed with a higher timeout, fewer assertions, a skipped test or a retry.
  • Never move a package to the isolated project to hide state a test leaves behind; clean up the state instead.

4. Measure again

Run the same command as in step 1, on the same machine, twice. Give each number from step 1 as before -> after, for example wall 41.2 s -> 6.8 s, and say which number moved for which reason.

Then run the changed folders' tests. The full pnpm check runs once, at the end of the work.

5. Report

The cause, the files changed, the numbers before and after, the coverage you kept or moved, and the commands you ran.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.