Skip to content

Conversation

@Kontinuation
Copy link
Member

@Kontinuation Kontinuation commented Oct 30, 2025

Ported changes are mostly for optimizing intersects:

We observed performance improvements after applying these patches. Now the performance of sedona-geo-generic-alg's intersects function is on par with the upstream georust/geo:

Benchmarking MultiPolygon intersects: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 7.8s or enable flat sampling.
MultiPolygon intersects time:   [141.71 ms 141.91 ms 142.08 ms]
                        change: [-54.400% -54.242% -54.080%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 10 measurements (20.00%)
  1 (10.00%) low mild
  1 (10.00%) high mild

Benchmarking MultiPolygon intersects 2: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 7.8s or enable flat sampling.
MultiPolygon intersects 2
                        time:   [141.70 ms 141.93 ms 142.25 ms]
                        change: [-58.568% -58.385% -58.220%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high severe

Benchmarking MultiPolygon intersects geo: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 7.1s or enable flat sampling.
MultiPolygon intersects geo
                        time:   [129.15 ms 129.41 ms 129.97 ms]
                        change: [-1.3094% -0.3470% +0.5022%] (p = 0.52 > 0.05)
                        No change in performance detected.
Found 2 outliers among 10 measurements (20.00%)
  2 (20.00%) high severe

Benchmarking MultiPolygon intersects geo 2: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 7.4s or enable flat sampling.
MultiPolygon intersects geo 2
                        time:   [132.93 ms 133.14 ms 133.48 ms]
                        change: [-0.8341% -0.3690% +0.0761%] (p = 0.15 > 0.05)
                        No change in performance detected.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high mild

Benchmarking MultiPolygon intersects wkb: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 8.2s or enable flat sampling.
MultiPolygon intersects wkb
                        time:   [149.24 ms 149.39 ms 149.68 ms]
                        change: [-58.540% -57.965% -57.446%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 10 measurements (20.00%)
  2 (20.00%) high severe

Benchmarking MultiPolygon intersects wkb aligned: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 8.2s or enable flat sampling.
MultiPolygon intersects wkb aligned
                        time:   [149.49 ms 149.72 ms 150.02 ms]
                        change: [-57.996% -57.703% -57.440%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high severe

Benchmarking MultiPolygon intersects wkb conv: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 9.5s or enable flat sampling.
MultiPolygon intersects wkb conv
                        time:   [170.85 ms 171.65 ms 173.49 ms]
                        change: [-49.706% -49.261% -48.785%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 10 measurements (20.00%)
  2 (20.00%) high severe

Rect intersects         time:   [27.692 µs 27.815 µs 27.954 µs]
                        change: [-10.597% -9.9531% -9.3407%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

LineString above Polygon
                        time:   [42.070 ns 42.183 ns 42.319 ns]
                        change: [-41.140% -40.905% -40.678%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 13 outliers among 100 measurements (13.00%)
  7 (7.00%) high mild
  6 (6.00%) high severe

LineString above Triangle
                        time:   [37.656 ns 37.710 ns 37.776 ns]
                        change: [-67.119% -66.992% -66.880%] (p = 0.00 < 0.05)
                        Performance has improved.

LineString around Rectangle
                        time:   [39.998 ns 40.141 ns 40.274 ns]
                        change: [-30.674% -30.411% -30.118%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild

long disjoint           time:   [4.5585 ms 4.5801 ms 4.6157 ms]
                        change: [-41.478% -41.120% -40.611%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
  3 (3.00%) high mild
  9 (9.00%) high severe

ls within poly          time:   [13.420 ns 13.458 ns 13.501 ns]
                        change: [-62.796% -62.671% -62.536%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild

ls within rect          time:   [865.31 ps 867.20 ps 869.17 ps]
                        change: [-77.619% -77.544% -77.467%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

Point intersects rect   time:   [31.254 µs 31.362 µs 31.495 µs]
                        change: [+1.5134% +2.1800% +2.8175%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 5 outliers among 50 measurements (10.00%)
  2 (4.00%) high mild
  3 (6.00%) high severe

Point intersects triangle
                        time:   [51.201 ms 51.340 ms 51.507 ms]
                        change: [-21.835% -21.424% -21.020%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 50 measurements (8.00%)
  4 (8.00%) high severe

Triangle intersects point
                        time:   [7.3176 ns 7.3347 ns 7.3549 ns]
                        change: [-2.7754% -2.3862% -2.0256%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 50 measurements (12.00%)
  4 (8.00%) high mild
  2 (4.00%) high severe

Triangle intersects point on edge
                        time:   [15.252 ns 15.271 ns 15.294 ns]
                        change: [-1.5220% -1.1374% -0.7697%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 5 outliers among 50 measurements (10.00%)
  4 (8.00%) high mild
  1 (2.00%) high severe

Benchmarking Point polygon intersects: Warming up for 3.0000 s
Warning: Unable to complete 50 samples in 5.0s. You may wish to increase target time to 7.6s, enable flat sampling, or reduce sample count to 20.
Point polygon intersects
                        time:   [5.9300 ms 5.9401 ms 5.9529 ms]
                        change: [-0.1076% +0.3396% +0.7799%] (p = 0.14 > 0.05)
                        No change in performance detected.
Found 6 outliers among 50 measurements (12.00%)
  3 (6.00%) high mild
  3 (6.00%) high severe

Benchmarking Point polygon intersects geo: Warming up for 3.0000 s
Warning: Unable to complete 50 samples in 5.0s. You may wish to increase target time to 7.6s, enable flat sampling, or reduce sample count to 20.
Point polygon intersects geo
                        time:   [5.9395 ms 5.9632 ms 5.9992 ms]
                        change: [+0.7289% +1.3617% +2.1782%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 2 outliers among 50 measurements (4.00%)
  1 (2.00%) high mild
  1 (2.00%) high severe

Benchmarking Point polygon intersects wkb: Warming up for 3.0000 s
Warning: Unable to complete 50 samples in 5.0s. You may wish to increase target time to 9.5s, enable flat sampling, or reduce sample count to 20.
Point polygon intersects wkb
                        time:   [7.4118 ms 7.4331 ms 7.4591 ms]
                        change: [-0.1375% +0.3810% +0.8415%] (p = 0.15 > 0.05)
                        No change in performance detected.
Found 5 outliers among 50 measurements (10.00%)
  4 (8.00%) high mild
  1 (2.00%) high severe

Point polygon intersects wkb conv
                        time:   [32.824 ms 32.901 ms 32.989 ms]
                        change: [+0.2233% +0.5778% +0.9195%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 6 outliers among 50 measurements (12.00%)
  4 (8.00%) high mild
  2 (4.00%) high severe

Distance computation uses intersects internally, so the performance of distance computation should be improved theoretically. However, I have not observed performance improvements by running the distance bench, probably because it only involves simple shapes.

…skip optimized intersects; mark PR #1377 SKIPPED
Renamed rectangle corner variables for clarity:
- lt/rb (left-top/right-bottom) → lb/rt (left-bottom/right-top)
- This makes variable names match their actual positions
- lb = min (left-bottom), rt = max (right-top)

Ported from georust/geo commits:
- a83b4d50: Merge pull request #1368
- bbacf118: rename rectangle corners

Tests: All 295 tests pass
Copy link
Member

@paleolimbot paleolimbot 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!

@Kontinuation Kontinuation marked this pull request as ready for review October 31, 2025 01:19
@Kontinuation Kontinuation requested a review from Copilot October 31, 2025 01:19
Copy link
Contributor

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 ports optimization changes from georust/geo to sedona-geo-generic-alg, primarily focusing on improving the performance of intersection operations. The changes include algorithm optimizations, improved implementations for specific geometry type intersections, and updates to use more idiomatic constructors for empty geometries.

  • Optimized polygon-polygon intersection logic to avoid redundant checks
  • Added specialized intersection implementations for Triangle and Rect with Polygon
  • Replaced verbose empty geometry constructors with concise .empty() calls

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
rust/sedona-geo-traits-ext/src/multi_polygon.rs Expanded trait implementations by removing macro usage and explicitly defining polygon access methods
rust/sedona-geo-generic-alg/src/algorithm/map_coords.rs Updated to use LineString::empty() instead of LineString::new(vec![])
rust/sedona-geo-generic-alg/src/algorithm/intersects/triangle.rs Added optimized Triangle-Polygon and Triangle-Rect intersection implementations with tests
rust/sedona-geo-generic-alg/src/algorithm/intersects/rect.rs Added optimized Rect-Polygon intersection implementation and refactored Line intersection logic
rust/sedona-geo-generic-alg/src/algorithm/intersects/polygon.rs Refactored polygon-polygon intersection with optimized algorithm and removed delegated implementations
rust/sedona-geo-generic-alg/src/algorithm/intersects/point.rs Updated georust/geo source commit reference
rust/sedona-geo-generic-alg/src/algorithm/intersects/mod.rs Updated source reference and added missing test coverage for Coord intersections
rust/sedona-geo-generic-alg/src/algorithm/intersects/line_string.rs Added specialized LineString intersection implementations for Polygon, MultiPolygon, Rect, and Triangle
rust/sedona-geo-generic-alg/src/algorithm/intersects/line.rs Updated georust/geo source commit reference
rust/sedona-geo-generic-alg/src/algorithm/intersects/coordinate.rs Updated georust/geo source commit reference
rust/sedona-geo-generic-alg/src/algorithm/intersects/collections.rs Updated georust/geo source commit reference
rust/sedona-geo-generic-alg/src/algorithm/dimensions.rs Updated documentation examples to use .empty() constructor
rust/sedona-geo-generic-alg/src/algorithm/coordinate_position.rs Updated test to use Polygon::empty() constructor
rust/sedona-geo-generic-alg/src/algorithm/centroid.rs Updated tests to use .empty() constructors for MultiLineString and MultiPolygon
rust/sedona-geo-generic-alg/benches/intersection.rs Added new benchmark cases for various intersection scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Kontinuation Kontinuation merged commit 3df327d into apache:main Oct 31, 2025
12 checks passed
@paleolimbot paleolimbot added this to the 0.2.0 milestone Nov 27, 2025
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