Skip to content

Conversation

@pjaap
Copy link
Member

@pjaap pjaap commented Jul 18, 2025

This reduces the wall time.

demo:

using ExtendableGrids, GridVisualizeTools

grid = uniform_refine(grid_unitcube(Tetrahedron3D), 6)

coords = grid[Coordinates]
cellnodes = grid[CellNodes]
func = ones(size(cellnodes, 2))

@benchmark marching_tetrahedra(coords, cellnodes, func, [[1.,1.,1.,-1.]], [])

yields

BenchmarkTools.Trial: 105 samples with 1 evaluation per sample.
 Range (min … max):  46.173 ms … 52.366 ms  ┊ GC (min … max): 0.00% … 2.72%
 Time  (median):     47.590 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   47.930 ms ±  1.352 ms  ┊ GC (mean ± σ):  0.60% ± 1.22%

       ██▂▂▄▄       ▂▂▂▂ ▆                                     
  █▆▄████████▆█▆▆▆█▄████▄██▁▁▄▁▄▄▆▁▁▁▄▄▁▆▄▆▁▁▆▁▄▁▄▁▄▁▁▄▁▁▁▁▁▄ ▄
  46.2 ms         Histogram: frequency by time          52 ms <

 Memory estimate: 5.89 MiB, allocs estimate: 84.

without @MArray and

BenchmarkTools.Trial: 141 samples with 1 evaluation per sample.
 Range (min … max):  33.983 ms … 39.415 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     35.359 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   35.589 ms ±  1.086 ms  ┊ GC (mean ± σ):  0.82% ± 1.51%

       █▁▁▄▄▆  ▃▁▆     ▃     ▁▃    ▁                           
  ▆▆▆▆▆██████▇▇███▆▇▇▆▇█▆▇▆▄▇██▇▇▄▄█▇▄▇▆▄▁▁▄▆▁▁▄▄▁▆▄▆▄▁▁▁▁▄▁▄ ▄
  34 ms           Histogram: frequency by time        38.5 ms <

 Memory estimate: 5.89 MiB, allocs estimate: 80.

with @MArray.

This is reduces wall time by about 25%.

The cn array is not used, and therefore removed.

@pjaap pjaap requested a review from j-fu July 18, 2025 15:01
@j-fu
Copy link
Member

j-fu commented Jul 18, 2025

Wow interesting didn't expect this, and for sure not this amount!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... ok for me

@j-fu j-fu requested a review from Copilot July 18, 2025 19:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the marching_tetrahedra function by replacing regular arrays with static arrays (@MArray) for small, fixed-size data holders to improve performance. The change reduces wall time by approximately 25% while maintaining the same memory usage.

  • Converts small fixed-size arrays to static arrays using @MArray macro
  • Removes unused cn array variable
  • Maintains same functionality with improved performance characteristics

@pjaap
Copy link
Member Author

pjaap commented Jul 21, 2025

I also checked Copilot's comments. This does not speed up the method. So I will leave the @MArray macro. I think it is better readable.

@pjaap pjaap merged commit 1099e09 into main Jul 21, 2025
11 checks passed
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.

3 participants