Skip to content

Conversation

@fderuiter
Copy link
Owner

⚡ Bolt: Optimized Marching Cubes Isosurface Extraction

💡 What:

  • Implemented a "Sliding Window" cache for voxel values in the extract_isosurface loop.
  • Reused the "Right Face" values (v1, v2, v5, v6) of the previous iteration as the "Left Face" values (v0, v3, v4, v7) of the current iteration.
  • Deferred the construction of corner_values and corner_pos arrays until after the edge_flags check confirms the voxel is not empty.

🎯 Why:

  • Memory reads were a bottleneck. Each voxel read 8 values, but 4 of them were already read in the previous iteration. This optimization reduces reads to 4 per voxel.
  • The majority of voxels in a typical SDF are empty (edge_flags == 0). Constructing arrays on the stack for these voxels was unnecessary overhead.

📊 Impact:

  • Reduces memory reads by 50% per voxel.
  • Reduces runtime by ~7% in the profile_isosurface benchmark (29ms -> 27ms).

microscopes Measurement:

  • Run cargo run --release --example profile_isosurface --manifest-path math_explorer/Cargo.toml to see the improvement.

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

Implements a sliding window optimization in `extract_isosurface` to reuse
corner values from the previous iteration, reducing memory reads by 50%.
Also defers the construction of `corner_values` and `corner_pos` arrays
until after the early exit check for empty voxels, reducing stack usage
and initialization overhead.

Benchmarks show a ~7% performance improvement (runtime reduced from
~29ms to ~27ms for a 128^3 grid).

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.

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.

2 participants