Skip to content

Use delta rather than markers in gridpoints_in_polygon#165

Open
gpeairs wants to merge 3 commits intomainfrom
gp/autofill-opt
Open

Use delta rather than markers in gridpoints_in_polygon#165
gpeairs wants to merge 3 commits intomainfrom
gp/autofill-opt

Conversation

@gpeairs
Copy link
Member

@gpeairs gpeairs commented Mar 6, 2026

gridpoints_in_polygon looks at one row of a grid at a time. For every polygon edge intersecting that row, it marks every grid point to the left of that edge, adding or subtracting 1 depending on the edge direction.

This just adds a delta at the first element and at the new edge, then does a prefix sum at the end. We also now avoid some other unnecessary allocations. The results are the same, verified against full designs, but we get ~3x improvement in benchmark times and huge improvement in allocations for large grids. Integration benchmarks ("coarse and fine") don't see the full speedup because they spend time on geometry construction.

Old:

ID time GC time memory allocations
["autofill", "coarse_and_fine"] 22.786 ms (5%) 41.56 MiB (1%) 381122
["autofill", "gridpoints_in_polygon", "3201x2401"] 28.507 ms (5%) 50.13 MiB (1%) 50596
["autofill", "gridpoints_in_polygon", "321x241"] 357.966 μs (5%) 683.22 KiB (1%) 4708
["autofill", "gridpoints_in_polygon", "33x25"] 22.950 μs (5%) 38.23 KiB (1%) 641

New:

ID time GC time memory allocations
["autofill", "coarse_and_fine"] 17.834 ms (5%) 27.58 MiB (1%) 324429
["autofill", "gridpoints_in_polygon", "3201x2401"] 9.131 ms (5%) 1.28 MiB (1%) 7406
["autofill", "gridpoints_in_polygon", "321x241"] 139.082 μs (5%) 63.93 KiB (1%) 923
["autofill", "gridpoints_in_polygon", "33x25"] 15.260 μs (5%) 22.60 KiB (1%) 271

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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