TS

TypeScript Performance

TypeScript/JavaScript runtime performance patterns

Details

Language / Topic
typescriptTypeScript
Category
Performance

Rules

balanced
- Use `for` loops or `for...of` instead of `forEach` or `map` in hot code paths for better performance.
- Avoid unnecessary object allocations inside loops to reduce garbage collection pressure.
- Use `Map` and `Set` for frequent insertions, deletions, and keyed sideups instead of plain objects or arrays.
- Cache results of expensive computations manually or use memoization techniques.
- Avoid synchronous blocking I/O methods; always use async/await equivalents.
- Debounce or throttle high-frequency events to prevent CPU spikes.
- Use `structuredClone` for deep copying instead of `JSON.parse(JSON.stringify())`.