6. Performance Optimization

This chapter covers techniques for maximizing NLSQ performance.

6.1. Chapter Overview

JIT Caching (10 min)

Understanding and optimizing JIT compilation caching.

Memory Management (10 min)

Memory pools, budgets, and efficient data handling.

Sparse Jacobians (10 min)

Leveraging sparsity for large problems.

Profiling (10 min)

Using TRFProfiler and identifying bottlenecks.

6.2. Performance Quick Tips

  1. Use GPU: 10-20x speedup for large datasets

  2. Reuse CurveFit: JIT cached between calls

  3. Use streaming: Memory-efficient for very large data

  4. Loosen tolerances: Trade precision for speed

  5. Profile first: Identify actual bottlenecks

# Fast pattern
fitter = CurveFit()  # Create once
for x, y in datasets:
    popt, pcov = fitter.curve_fit(model, x, y)  # JIT reused