Skip to content

Consider caching strategy for repeated Poisson bracket calls #37

@anjor

Description

@anjor

Background

In typical KRMHD time-stepping, the Poisson bracket is called repeatedly with the same field pairs (e.g., {φ, A∥} computed at each RK4 substep). Currently, each call recomputes:

  1. Four derivative transforms (∂f/∂x, ∂f/∂y, ∂g/∂x, ∂g/∂y)
  2. Four inverse FFTs
  3. One forward FFT
  4. Dealiasing

Potential Optimizations

  1. Cache derivatives: If f or g unchanged, reuse ∂f/∂x, ∂f/∂y
  2. Batch operations: Compute multiple brackets in parallel (vmap)
  3. Lazy evaluation: Use SpectralField2D/3D lazy caching for derivatives
  4. JIT compilation: Ensure XLA optimizes repeated calls

Investigation Needed

  • Profile typical time-stepping workload (RK4 with 3-4 fields)
  • Measure cache hit rate if derivatives were cached
  • Benchmark batch bracket evaluation vs sequential
  • Check if JAX XLA already optimizes this pattern
  • Estimate memory overhead of caching derivatives

Decision Criteria

Only implement if:

  • Profiling shows bracket is >50% of runtime (expected)
  • Cache provides >20% speedup
  • Memory overhead acceptable (<2x current usage)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions