performance-optimizing
Performance Optimizing
Optimization Workflow
- Measure first - Don't optimize without data
- Find bottlenecks - Profile to identify hot paths
- Fix the biggest issue - Pareto principle (80/20)
- Measure again - Verify improvement
- Document - Record what changed and why
Common Bottlenecks
Database
| Problem | Solution |
|---|---|
| N+1 queries | Eager loading, batching |
| Missing indexes | Add indexes on WHERE/JOIN columns |
| Full table scans | Optimize queries, add indexes |
| Over-fetching | Select only needed columns |
// Bad - N+1 queries
for (const user of users) {
const posts = await db.posts.findByUserId(user.id);
}
// Good - single query with join
const usersWithPosts = await db.users.findAll({
include: ['posts'],
});
Memory
| Problem | Solution |
|---|---|
| Memory leaks | Clear references, use WeakMap |
| Large objects | Stream processing, pagination |
| Duplicated data | Normalize, use references |
CPU
| Problem | Solution |
|---|---|
| Blocking operations | Use async/workers |
| Redundant computation | Memoization, caching |
| Inefficient algorithms | Better data structures |
// Bad - O(n) lookup on every iteration
for (const item of items) {
if (list.includes(item.id)) { ... }
}
// Good - O(1) lookup with Set
const idSet = new Set(list);
for (const item of items) {
if (idSet.has(item.id)) { ... }
}
Network
| Problem | Solution |
|---|---|
| Too many requests | Batching, HTTP/2 |
| Large payloads | Compression, pagination |
| No caching | HTTP caching, CDN |
Quick Wins
- Add indexes on frequently queried columns
- Enable compression (gzip/brotli)
- Implement caching at appropriate layers
- Use pagination for large datasets
- Lazy load non-critical resources
Anti-Patterns
- Premature optimization without measurement
- Micro-optimizations that hurt readability
- Caching everything (cache invalidation is hard)
- Optimizing cold paths
More from mrwogu/promptscript
refactoring
Improves code structure without changing behavior. Use when cleaning up code, reducing complexity, or when asked to refactor.
1pull-requesting
Creates well-structured pull requests with clear descriptions. Use when creating PRs, preparing changes for review, or when asked to open a pull request.
1code-reviewing
Reviews code for bugs, security issues, and quality improvements. Use when reviewing pull requests, checking code quality, or when asked to review changes.
1documenting
Creates clear, maintainable documentation for code and APIs. Use when writing README files, API docs, code comments, or when asked to document code.
1testing-code
Writes comprehensive tests following AAA pattern. Use for unit and integration tests.
1debugging
Systematically debugs issues using scientific method. Use when investigating bugs, fixing errors, or when something isn't working as expected.
1