Skip to content

⚡ Profiler: Turing System Loop Fusion#437

Draft
fderuiter wants to merge 3 commits intomainfrom
profiler/turing-loop-fusion-4639716987234036989
Draft

⚡ Profiler: Turing System Loop Fusion#437
fderuiter wants to merge 3 commits intomainfrom
profiler/turing-loop-fusion-4639716987234036989

Conversation

@fderuiter
Copy link
Owner

📉 The Bottleneck:
The TuringSystem::step function was performing two passes over large arrays for every simulation step: one for diffusion (calculating Laplacian) and one for reaction/integration. This caused excessive memory traffic (6 reads + 4 writes per element).

🚀 The Boost:
Before: 44.11µs per step
After: 23.96µs per step
Gain: 45.6% improvement.

💻 Technical Detail:

  • Extended SpatialDiffusion trait with apply_step to allow strategies to fuse operations.
  • Implemented apply_step in FiniteDifference1D to compute diffusion and reaction in a single loop.
  • Utilized register-based sliding window to avoid writing/reading intermediate diffusion terms to memory.

🧪 Verification:

  • Tests passed (including regression tests).
  • Benchmark bench_morphogenesis created and verified.

PR created automatically by Jules for task 4639716987234036989 started by @fderuiter

- Extended `SpatialDiffusion` trait with `apply_step`.
- Implemented fused loop in `FiniteDifference1D` to reduce memory bandwidth.
- Updated `TuringSystem` to use the optimized path.
- Added benchmark `examples/bench_morphogenesis.rs`.
- Documented in `.jules/profiler.md`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

fderuiter and others added 2 commits February 6, 2026 19:40
- Compacted multiline function calls in `math_explorer/examples/bench_morphogenesis.rs` and `math_explorer/src/biology/morphogenesis.rs`.
- Fixed indentation in loop body.
- Applied changes to match `cargo fmt -- --check` output from CI.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
- Added `#[allow(clippy::too_many_arguments)]` to `SpatialDiffusion::apply_step`
- This method is a performance-critical hot path (loop fusion) where bundling arguments would be counter-productive.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant