test-perf-leaks

CPU-profile and leak-detect existing vitest suites via env-gated instrumentation.

518|49|Updated Apr 7, 2021
One-click install
npx skills add https://github.com/dxos/dxos --skill test-perf-leaks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-perf-leaks
Source: https://github.com/dxos/dxos/tree/main/.agents/skills/test-perf-leaks
Command: npx skills add https://github.com/dxos/dxos --skill test-perf-leaks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Node test suites that run slowly or grow memory across a run are hard to diagnose without modifying test code. This Skill instruments the shared vitest node project through opt-in environment variables, producing V8 CPU profiles and heap snapshots from an existing suite with zero edits to the test file.

Core Features & Use Cases

  • CPU Profiling: Set DX_PROFILE_TESTS to emit a V8 .cpuprofile via Node --cpu-prof, viewable in Chrome DevTools or speedscope to find hotspots.
  • Leak Detection: Set DX_DEBUG_LEAKS to inject a setup file that captures before/after heap snapshots plus a per-test heapUsed slope in heap-samples.ndjson.
  • Use Case: A suite in the echo or sdk package keeps growing in memory across tests. Run it with DX_DEBUG_LEAKS=1, read the heap slope for a monotonic rise, then diff the before/after snapshots in DevTools Comparison view to find the retainer chain holding the leaked objects.

Quick Start

Run DX_DEBUG_LEAKS=1 moon run <pkg>:test --force -- src/foo.test.ts to leak-check a single vitest suite and inspect the generated heap snapshots.

Frequently Asked Questions about test-perf-leaks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I CPU profile a vitest test suite?

Set DX_PROFILE_TESTS=1 and run moon run <pkg>:test --force -- src/foo.test.ts. This emits a V8 .cpuprofile into the package's profiles directory, which you can open in Chrome DevTools Performance panel or speedscope to inspect self time.

How to detect memory leaks in node tests?

Set DX_DEBUG_LEAKS=1 and run the suite with moon run <pkg>:test --force -- src/foo.test.ts. It writes before/after heap snapshots and a per-test heapUsed slope in heap-samples.ndjson; a monotonic rise across tests indicates a real leak.

Does this work with browser or workerd test suites?

No, the instrumentation is wired only into the node vitest project created by createNodeProject. Browser, storybook, and workerd suites are not supported, and profiling the running Composer app requires separate app-side heap tooling.

Why must I pass --force when running the profiled test?

The env vars are declared as moon task inputs, so a repeat run with identical inputs would hydrate the cached result and skip vitest entirely, producing no fresh profile. The --force flag re-executes the task unconditionally.

Why should I target only one test file for leak detection?

The leak model assumes a single suite in one process, giving one clean before/after snapshot pair. Multiple files would create ambiguity about which file ran last and mix heap samples across suites.