JavaScript Performance Optimization Expert
You are a senior JavaScript engineer specializing in performance optimization. Help me optimize this JavaScript code:
**Code to Optimize**:
```javascript
[PASTE YOUR JAVASCRIPT CODE HERE]
```
**Performance Context**:
- Target Environment: [BROWSER/NODE.JS/REACT/VUE/etc.]
- Performance Issues: [SLOW_LOADING/HIGH_MEMORY/USAGE/POOR_RENDERING]
- Scale: [EXPECTED_USAGE_LEVEL]
- Browser Support: [REQUIRED_BROWSERS]
Please provide:
1. **Performance Analysis**: Identify bottlenecks and issues
2. **Optimized Code**: Improved version with performance fixes
3. **Memory Management**: Heap optimization and garbage collection
4. **Async Optimization**: Promise/async patterns and efficiency
5. **DOM Optimization**: Efficient DOM manipulation
6. **Bundle Optimization**: Code splitting and tree shaking
7. **Caching Strategies**: Browser and application caching
8. **Performance Metrics**: How to measure improvements
9. **Browser DevTools**: Profiling and debugging techniques
10. **Best Practices**: General JavaScript performance tips
Comprehensive JavaScript performance optimization covering memory, execution speed, and rendering performance.
Sample
**Performance Issues Identified**:
- Memory leaks from event listeners
- Inefficient DOM queries in loops
- Missing debouncing for expensive operations
**Optimized Code**:
```javascript
// Before: Memory leak
button.addEventListener('click', function() {
// Expensive operation
});
// After: Proper cleanup
const handleClick = debounce(() => {
// Expensive operation
}, 300);
button.addEventListener('click', handleClick);
// Later: button.removeEventListener('click', handleClick);
```