Skip to content
Skills Library
Programming · Testing

test-performance

/test-performance

Use when optimizing test suite performance — database setup, seeder optimization, parallel testing, CI pipeline efficiency, or RefreshDatabase alternatives.

Licence
MIT
Last repository change
26.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use when optimizing test suite performance — database setup, seeder optimization, parallel testing, CI pipeline efficiency, or RefreshDatabase alternatives.

Original author description

Use when optimizing test suite performance — database setup, seeder optimization, parallel testing, CI pipeline efficiency, or RefreshDatabase alternatives.

How it works

  1. When to use
  2. Procedure: Analyze test performance
  3. Related project docs
  4. Output format
  5. Gotcha
  6. Do NOT
  7. Where the time goes, per ecosystem
Original SKILL.md headings · 185 lines, 880 words
SKILL.md preview
---
model_tier: medium
name: test-performance
description: "Use when optimizing test suite performance — database setup, seeder optimization, parallel testing, CI pipeline efficiency, or RefreshDatabase alternatives."
domain: quality
framework: laravel
workspaces:
  - engineering
packs:
  - engineering-base
---

# test-performance

## When to use

Use this skill when:

- Tests are running too slowly (locally or in CI)
- Database setup/teardown is a bottleneck
- Parallel testing needs optimization
- Seeders need performance analysis
- CI pipeline test jobs need to be faster
- Investigating flaky tests caused by database state

## Procedure: Analyze test performance

### 1. Measure baseline

Before optimizing, always measure:

```bash
# Count tests per suite
find tests/ app/Modules/*/Tests/ -name "*.php" | xargs grep -l "it(" | wc -l

# Count by suite type
grep -rh "it(" tests/Unit/ app/Modules/*/Tests/Unit/ --include="*.php" | wc -l
grep -rh "it(" tests/Component/ app/Modules/*/Tests/Component/ --include="*.php" | wc -l
grep -rh "it(" tests/Integration/ app/Modules/*/Tests/Integration/ --include="*.php" | wc -l

# Count migrations
ls database/migrations/*.php | wc -l

# Count seeders
find database/seeders database/seeder-data -name "*.php" -path "*/data/*" | wc -l
```

### 2. Identify bottlenecks

The typical test lifecycle is:

```
Process Start → Migrate → Seed → [Test → Rollback] × N → Process End
                 ↑ expensive (once per worker)
```

Check these areas in order of typical impact:

| Area | What to check | Typical impact |
|------|--------------|---------------|
| **Migration count** | How many CREATE TABLE statements? | High if >20 |
| **Schema dump** | Is `database/schema/` used? | High if missing |
| **Seeder INSERT method** | Individual `save()` vs bulk insert? | Medium |
| **Truncation** | Per-seeder truncate vs centralized? | Low (but causes correctness issues) |
| **Connection discovery** | Dynamic `getPdo()` probing? | Low |
| **Parallel worker setup** | Does each worker re-migrate? | High |

### 3. Optimization strategies (ordered by ROI)

#### A. Schema Dump (highest ROI)

Laravel's `schema:dump` consolidates all migrations into one SQL file.
Instead of running N individual CREATE TABLE migrations, it loads one SQL dump.

```bash
php artisan schema:dump --database=api_database
# Generates database/schema/api_database-schema.sql
```

**Savings:** 58 migrations → 1 SQL load = ~10-25s per worker.

#### B. Template DB Cloning (high ROI for parallel tests)

Instead of each parallel worker running migrate+seed independently:
1. Prepare ONE template database (migrate + seed)
2. Clone template for each worker via mysqldump

```bash
# Prepare template
php artisan migrate:fresh --database=template_db
php artisan db:seed --database=template_db

# Clone per worker
mysqldump template_db | mysql worker_db_test_1
```

**Savings:** Eliminate per-worker migrate+seed entirely.

#### C. Skip Migrate+Seed Flag (high ROI for local dev)

Add a config flag to skip database setup when DB is already prepared:

```php
// config/testing.php
'skip_migrate_seed' => EnvHelper::boolean('TESTING_SKIP_MIGRATE_SEED', false),
```

Developer workflow: `make migrate-testing` once, then `make test-quick` repeatedly.

#### D. Bulk Inserts in Seeders (medium ROI)

Replace individual `$model->save()` with bulk insert:

```php
// Before: N INSERT statements
foreach ($data as $row) {
    $model = new MyModel($row);
    $model->save();
}

// After: 1 INSERT statement
MyModel::insert($data);
$models = MyModel::whereIn('id', $ids)->get();
```

#### E. Centralize Truncation (correctness fix)

Per-seeder truncation is redundant after `migrate:fresh` and causes:
- Non-deterministic ordering (lazy init triggers truncate)
- Ghost data bugs (locally passes, CI fails)

Make truncation configurable, default off:

```php
// config/testing.php
'seed_truncate' => EnvHelper::boolean('DB_SEED_TRUNCATE', false),
```

#### F. Static Connection Discovery (cleanup)

Replace dynamic `getPdo()` probing with explicit config:

```php
// config/testing.php
'connections_to_transact' => ['api_database', 'customer_database'],
```

### 4. CI-specific optimizations

- **MariaDB tmpfs:** Mount data dir on RAM disk for zero I/O latency
- **Shared DB prep:** One CI job prepares DB, test jobs clone from it
- **Cache test DBs:** Skip re-migration if migration files haven't changed
- **Separate suites:** Run no-DB tests (Unit) on cheaper runners

## Related project docs

- `agents/reference/docs/seeders.md` — seeder conventions (if exists)

## Output format

1. Optimized test configuration or seeder with timing comparison
2. Parallelization or caching improvements applied

## Gotcha

- Don't use RefreshDatabase when DatabaseTransactions suffices — full refresh is 10x slower.
- The model forgets that parallel tests share the database — use unique identifiers in test data.
- Seeder optimization has the highest ROI — a 2s seeder running 100 times = 200s wasted.
- Don't add indexes to test databases just for test performance — the real fix is better test design.


## Do NOT

- Do NOT use RefreshDatabase when DatabaseTransactions works — 10x slower.
- Do NOT run full test suite on every code change — use `--filter`.
- Do NOT add test-only indexes — fix test design instead.
- Do NOT disable parallel testing to "fix" flaky tests — fix the root cause.

## Where the time goes, per ecosystem

The diagnosis above is PHPUnit-shaped. The method — measure before optimising,
find the slowest tests first, separate setup cost from assertion cost —
transfers; the instrument does not. Resolve the runner with
`resolve_toolchain` and read its `ecosystems`:

| `ecosystems` | Slowest-test instrument | The usual first cause |
|---|---|---|
| `php` | `--profile` / Pest's duration column | database refresh per test |
| `js` | `vitest --reporter=verbose`, `jest --detectOpenHandles` | module transform and a leaked handle |
| `python` | `pytest --durations=20` | session-scoped fixtures rebuilt per test |
| `go` | `go test -v`, `-cpuprofile`, `-race` for the slow-and-flaky pair | a `TestMain` that starts real I/O |

`go test` caches a package's result until its inputs change, so a suite that
looks fast on the second run may not have run at all — `-count=1` defeats the
cache when you are measuring.
Files in this package (2)
  • SKILL.md 6 KB
  • evals/triggers.json 3 KB

Versions

The database has no other skills named test-performance.

Database snapshot: 13.11.2026 · package version 0841a2093e2d (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100laravel-testing
    Write Pest feature tests with RefreshDatabase, mock external services, and create test data with Eloquent Factories in Laravel. Use when adding HTTP tests, configuring SQLite in-memory test database, or mocking payment services.
  • 100qe-performance-testing
    Test application performance, scalability, and resilience. Use when planning load testing, stress testing, or optimizing system performance.
  • 100gds-performance-test
    Design game performance testing strategy. Use when the user says "performance test" or "benchmark
  • 100seed-test-data
    [Dev Data] Use when a workflow step or the user asks for idempotent QC happy-path seeders using public commands. --mode=review audits seeder conventions read-only.
  • 100seed-test-data
    [Dev Data] Use when a workflow step or the user asks for idempotent QC happy-path seeders using public commands. --mode=review audits seeder conventions read-only.
  • 100spike-test-setup
    Configure spike test setup operations. Auto-activating skill for Performance Testing. Triggers on: spike test setup, spike test setup Part of the Performance Testing skill category. Use when writing or running tests. Trigger with phrases like "spike test setup", "spike setup", "spike".

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.