Course/Chapter 9/5. Performance Optimization
    advanced
    Chapter 9: Troubleshooting & Debugging

    5. Performance Optimization

    Speed up slow workflows.

    15m Lesson 5 of 5

    When workflows process large datasets or make many API calls, performance optimization becomes critical.

    Optimization Techniques

    1. Batch processing: Use Split In Batches to process items in chunks
    2. Caching: Store frequently-accessed data to avoid repeated API calls
    3. Parallel execution: Split work across parallel branches
    4. Data pruning: Remove unnecessary fields early in the workflow
    5. Pagination: Process paginated API results efficiently

    Identifying Bottlenecks

    Check the execution time per node in the execution log. The slowest nodes are your optimization targets.

    Memory Management

    Large datasets can exhaust n8n's memory. Process items in batches and remove unneeded fields early to reduce memory footprint.

    Code Examples

    Efficient Batch Processing Pattern
    javascript
    // Process 1000+ items without memory issues
    // Use Split In Batches node set to batch size of 50
    
    // In Code node after batch processing:
    const batch = $input.all();
    
    // Remove unnecessary fields to save memory
    const slim = batch.map(item => ({
      json: {
        id: item.json.id,
        email: item.json.email,
        status: item.json.status
        // Don't carry large fields like 'description' or 'history'
      }
    }));
    
    // Add delay between batches to respect rate limits
    await new Promise(r => setTimeout(r, 1000));
    
    return slim;

    Pro Tips

    • 💡Profile your workflow by checking execution times per node — optimize the slowest nodes first
    • 💡Use Split In Batches with a batch size of 50-100 for most APIs
    • 💡Remove large unused fields early in the workflow to reduce memory usage

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What is the first step in optimizing a slow workflow?

    2. What is a good default batch size for most APIs?

    Pass the quiz above to unlock lesson completion