Skip to content

Conversation

@marcosdanieldasilva
Copy link

This PR adds a major performance optimization for finding indices on a TransformedGrid, specifically when it has a non-invertible SequentialTransform (like a Rotate followed by a Morphological transform).

Previously, this situation would fall back to the generic findall(intersects(geometry), domain) method, which is extremely slow because it must perform a costly intersection check for every single cell.

This new, specialized method implements a much faster "partial revert" strategy. It introspects the transform sequence, finds the invertible component (using isinvertible), and reverts the input geometry using only that part. This "un-transforms" the geometry back to the original grid's coordinate space, allowing it to call the existing, highly-optimized indices(grid.mesh, ...) function on the simple, non-deformed grid. A new test is included to validate this exact scenario.

Copy link
Member

@juliohm juliohm left a comment

Choose a reason for hiding this comment

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

Thank you @marcosdanieldasilva !

Added a few suggestions to generalize the code:

  1. The transform can have multiple steps, so we need to combine all the revertible ones into a new transform in reverse order.
  2. We can then just apply the created transform to the geometry.

We still need to check if any transform step needs special treatment.

@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.52%. Comparing base (7c2fbc3) to head (cfb2407).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1264      +/-   ##
==========================================
- Coverage   87.90%   87.52%   -0.38%     
==========================================
  Files         197      197              
  Lines        6240     6246       +6     
==========================================
- Hits         5485     5467      -18     
- Misses        755      779      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

marcosdanieldasilva and others added 4 commits November 1, 2025 21:15
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
marcosdanieldasilva and others added 16 commits November 1, 2025 21:51
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
@github-actions
Copy link
Contributor

Benchmark Results (Julia vlts)

Time benchmarks
master 897644d... master / 897644d...
clipping/SutherlandHodgman 3.69 ± 0.18 μs 3.77 ± 1.5 μs 0.979 ± 0.39
discretization/simplexify 26.4 ± 2.5 ms 27.7 ± 2.3 ms 0.954 ± 0.12
intersection/ray-triangle 0.05 ± 0.01 μs 0.05 ± 0.01 μs 1 ± 0.28
sideof/ring/large 6.53 ± 0.031 μs 6.53 ± 0.01 μs 1 ± 0.005
sideof/ring/small 0.05 ± 0.001 μs 0.05 ± 0.001 μs 1 ± 0.028
topology/half-edge 2.73 ± 0.045 ms 2.72 ± 0.037 ms 1.01 ± 0.021
winding/mesh 0.0424 ± 0.0022 s 0.0429 ± 0.0021 s 0.988 ± 0.07
time_to_load 1.54 ± 0.022 s 1.52 ± 0.0076 s 1.01 ± 0.016
Memory benchmarks
master 897644d... master / 897644d...
clipping/SutherlandHodgman 0.053 k allocs: 4.97 kB 0.053 k allocs: 4.97 kB 1
discretization/simplexify 0.226 M allocs: 21.8 MB 0.226 M allocs: 21.8 MB 1
intersection/ray-triangle 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/large 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/small 0 allocs: 0 B 0 allocs: 0 B
topology/half-edge 18.1 k allocs: 2.92 MB 18.1 k allocs: 2.92 MB 1
winding/mesh 0.231 M allocs: 23 MB 0.231 M allocs: 23 MB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

@github-actions
Copy link
Contributor

Benchmark Results (Julia v1)

Time benchmarks
master 897644d... master / 897644d...
clipping/SutherlandHodgman 2.6 ± 0.25 μs 2.6 ± 0.29 μs 1 ± 0.15
discretization/simplexify 23.5 ± 3.8 ms 23.9 ± 4 ms 0.984 ± 0.23
intersection/ray-triangle 0.06 ± 0.009 μs 0.05 ± 0.001 μs 1.2 ± 0.18
sideof/ring/large 6.84 ± 0.011 μs 6.78 ± 0.021 μs 1.01 ± 0.0035
sideof/ring/small 0.06 ± 0 μs 0.061 ± 0.01 μs 0.984 ± 0.16
topology/half-edge 2.76 ± 0.18 ms 2.78 ± 0.17 ms 0.994 ± 0.091
winding/mesh 0.0405 ± 0.0029 s 0.0403 ± 0.0031 s 1 ± 0.1
time_to_load 1.48 ± 0.013 s 1.48 ± 0.011 s 1 ± 0.011
Memory benchmarks
master 897644d... master / 897644d...
clipping/SutherlandHodgman 0.064 k allocs: 5.55 kB 0.064 k allocs: 5.55 kB 1
discretization/simplexify 0.321 M allocs: 21.7 MB 0.321 M allocs: 21.7 MB 1
intersection/ray-triangle 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/large 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/small 0 allocs: 0 B 0 allocs: 0 B
topology/half-edge 25.9 k allocs: 3.17 MB 25.9 k allocs: 3.17 MB 1
winding/mesh 0.326 M allocs: 22.9 MB 0.326 M allocs: 22.9 MB 1
time_to_load 0.145 k allocs: 11 kB 0.145 k allocs: 11 kB 1

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