Loading...
Loading...
Profile CPU performance of tests and browser tests in elements package. Use when investigating performance issues, optimizing test execution, or when the user mentions profiling, performance analysis, hotspots, or slow tests.
npx skill4agent add editframe/skills profile-tests# Built-in profiling for all browser tests
./scripts/browsertest --profile
# Profile specific test file
./scripts/browsertest --profile packages/elements/src/preview/renderTimegroupToCanvas.browsertest.ts
# Profile with test pattern
./scripts/browsertest --profile -t "batch capture"# Full analysis with unified profiling library
npx tsx scripts/profile-browsertest.ts \
packages/elements/src/preview/renderTimegroupToCanvas.browsertest.ts
# Get JSON output for LLM analysis
npx tsx scripts/profile-browsertest.ts \
packages/elements/src/preview/renderTimegroupToCanvas.browsertest.ts \
--json
# Focus on specific file
npx tsx scripts/profile-browsertest.ts \
packages/elements/src/preview/renderTimegroupToCanvas.browsertest.ts \
--focus renderToImage \
--json# Profile a scenario in sandbox
./scripts/ef profile EFCanvas basic --json
# With pattern detection
./scripts/ef profile EFCanvas basic --json --verbose
# Compare against baseline
./scripts/ef profile EFCanvas basic \
--baseline .profiles/baseline.cpuprofile \
--json# For browser tests
npx tsx scripts/profile-browsertest.ts \
packages/elements/src/preview/renderTimegroupToCanvas.browsertest.ts \
--json > profile.json
# For scenarios
./scripts/ef profile EFCanvas basic --json > profile.json{
"hotspots": [
{
"rank": 1,
"functionName": "updateFrame",
"file": "EFTimegroup.ts",
"line": 234,
"selfTimeMs": 45.2,
"selfTimePct": 31.1,
"callCount": 234
}
],
"byFile": [
{ "file": "EFTimegroup.ts", "timeMs": 82.1, "timePct": 56.5 }
],
"recommendations": [
"• updateFrame called 234 times - consider caching"
],
"patterns": [
{
"name": "Hot Loop Detected",
"severity": "high",
"suggestion": "Review loop logic..."
}
]
}selfTimePct > 15%callCount > 100selfTimePct > 5%timePct > 40%severity: "high"# Save baseline before changes
./scripts/ef profile EFCanvas basic \
--save .profiles/baseline-$(date +%Y%m%d-%H%M%S).cpuprofile
# After optimization, compare
./scripts/ef profile EFCanvas basic \
--baseline .profiles/baseline-TIMESTAMP.cpuprofile \
--jsonselfTimeDiffMsselfTimeDiffMs| Metric | Meaning | Use For |
|---|---|---|
| Time in function itself (excluding callees) | Direct optimization target |
| Percentage of total profile time | Prioritization (>15% = critical) |
| Times function appears in call stacks | Caching/memoization decisions |
| Profile samples that caught function | Loop detection (>200 = tight loop) |
// Before
function expensiveCalculation(x: number) {
return /* complex math */;
}
// After
const cache = new Map<number, number>();
function expensiveCalculation(x: number) {
if (cache.has(x)) return cache.get(x)!;
const result = /* complex math */;
cache.set(x, result);
return result;
}// Before
function processAll() {
// All work done synchronously
loadData();
transformData();
validateData();
saveData();
}
// After
function processAll() {
loadData(); // Only critical work
queueMicrotask(() => {
transformData();
validateData();
saveData();
});
}// Before
for (const item of items) {
container.appendChild(createItem(item)); // Multiple reflows
}
// After
const fragment = document.createDocumentFragment();
for (const item of items) {
fragment.appendChild(createItem(item));
}
container.appendChild(fragment); // Single reflow./scripts/ef profile EFCanvas basic./scripts/ef profile EFCanvas basic --json./scripts/ef profile EFCanvas basic --json --verbosenpx tsx scripts/profile-playback.ts \
--project improv-edit \
--duration 5000 \
--jsonnpx tsx scripts/profile-export.ts \
--project design-catalog \
--jsonnpx tsx scripts/profile-load.ts \
--project improv-edit \
--jsonef openhitCountelements/PROFILING.mdelements/LLM_PROFILING_GUIDE.mdelements/PROFILING_IMPLEMENTATION_SUMMARY.mdpackages/elements/src/profiling/