One-click analysis of project performance bottlenecks, outputting prioritized optimization suggestions.
Overview
Scan project code and configuration to detect performance issues: bundle size, dependency bloat, large files, unoptimized assets. Output an actionable optimization suggestion report sorted by impact level.
When to Use
- User wants to analyze project performance
- User mentions bundle size, slow loading, or performance optimization
- User wants to know which dependencies are slowing down the project
- User inputs
/performance-profiler - User wants to reduce bundle size for faster page loads
- User wants to find and remove unused dependencies
- User wants to check for barrel file impact on tree-shaking
- User wants performance optimization recommendations
When NOT to Use:
- User wants runtime profiling (requires dedicated APM tools like New Relic, Datadog)
- User wants load testing (use k6, Locust, or Apache Bench)
- User only wants to view code coverage (use coverage tools like Istanbul, coverage.py)
- User wants to optimize database queries (use EXPLAIN plans, slow query logs)
- User wants to check Core Web Vitals (use Lighthouse, PageSpeed Insights)
Core Pattern
Step 1: Detect project type
| Detect files | Project type | Analysis focus |
|---|---|---|
package.json |
Node.js / frontend | bundle size, dependency count, tree-shaking |
go.mod |
Go | Binary size, dependency count |
requirements.txt / pyproject.toml |
Python | Dependency count, duplicate dependencies |
Step 2: Analyze dependencies
# Node.js
if command -v node >/dev/null 2>&1; then
# 尝试 cost-of-modules,如果失败则使用替代方案
if npx --yes cost-of-modules 2>/dev/null; then
echo "使用 cost-of-modules 分析完成"
else
echo "⚠️ cost-of-modules 不可用,使用替代方案"
cat package.json | python3 -c "
import sys,json
d=json.load(sys.stdin)
deps=d.get('dependencies',{})
dev_deps=d.get('devDependencies',{})
print(f'Direct Dependencies: {len(deps)}')
print(f'Dev Dependencies: {len(dev_deps)}')
print(f'Total: {len(deps) + len(dev_deps)}')
# 列出前 10 个依赖
print('Top dependencies:')
for i, (name, ver) in enumerate(list(deps.items())[:10]):
print(f' {name}: {ver}')
"
fi
else
echo "⚠️ Node.js 未安装,跳过 Node.js 依赖分析"
fi
# Go
if command -v go >/dev/null 2>&1; then
echo "Go dependencies:"
go list -m all 2>/dev/null | tail -n +2 | wc -l || echo "0"
else
echo "⚠️ go 未安装,跳过 Go 依赖分析"
fi
# Python
if command -v python3 >/dev/null 2>&1; then
echo "Python dependencies:"
grep -cvE '^\s*(#|$)' requirements.txt 2>/dev/null || echo "0"
else
echo "⚠️ python3 未安装,跳过 Python 依赖分析"
fi
Statistics (corresponding to templates/report.md variables):
dep_count: direct dependency count (Nodelen(dependencies)/ Gogo list -m allcount / Python requirements line count)total_dep_count: total count including transitive dependencies (parsepackage-lock.json/go list -m all/pip list)outdated_count: outdated dependency count (npm outdated --json/go list -m -u all/pip list --outdated)health_score: overall score (dependency scale, outdated ratio, redundancy, 0-100)deps[].size: package size (from cost-of-modules or bundlephobia; leave blank if unavailable)- Duplicate dependencies (different packages introducing different versions of the same dependency)
- Possible redundant dependencies
Step 3: Scan code patterns
Frontend/Node.js focus:
- Check whether
import/requirehas a barrel file (index.tsre-exports all modules) - Check for large static files (images/fonts >500KB)
- Check for unused CSS/JS files
- Check
next.config.js/vite.config.tsoptimization configuration
Go focus:
- Check for unnecessary
init()functions - Check value passing of large structs (should use pointers)
Python focus:
- Check for
import * - Check for synchronous I/O in async contexts
Step 4: Generate report
Use templates/report.md template, output:
- Overview — dependency count, project health score
- High priority — issues with the greatest impact (bundle bloat, redundant dependencies)
- Medium priority — code-level optimization points
- Low priority — suggested improvements
- Specific fix commands — each issue comes with an executable fix command
Quick Reference
/performance-profiler # 分析当前项目,输出优化建议报告
Common Mistakes
| Mistake | Correct approach | Reason |
|---|---|---|
| Only looking at dependency count without looking at size | Analyze package size as well | 10 small packages may be better than 1 large package |
| Suggest deleting all devDependencies | devDependencies do not go into production | They do not affect online performance |
| Ignore the lock file | Analyze the actual dependency tree in the lock file | package.json declarations ≠ actual installation |
| Do not distinguish between production/development dependencies | Focus on analyzing dependencies | devDependencies do not affect the bundle |
| Ignore the impact of barrel files | Check index.ts re-export patterns | Barrel files prevent tree-shaking and greatly increase the bundle |
| Do not consider code splitting | Check dynamic import usage | Loading all code in a single chunk affects first-screen |
| Recommend removing all duplicate dependencies | Analyze actual usage before deciding | Some are peer dependencies that must be kept |
| Only analyze the frontend, not the backend | Analyze both frontend and backend for full-stack projects | Go/Python also have performance issues |
| Skip lock file analysis | Parse the lock file to obtain the complete dependency tree | Fewer direct dependencies does not mean fewer transitive dependencies |