Skip to content

Conversation

@michaelkirk
Copy link
Member

@michaelkirk michaelkirk commented Mar 4, 2025

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

I broke this in 44816eb (merged yesterday, not yet released) by attempting to reuse the bbox from the geometry graph's RTree.

The problem was that the RTree only contains the Geometry's segments, but Point and MultiPoint have no segments - they're zero-dimensional geometries.

I don't often use Relate with zero dimensional geometries, so it's only luck that an unrelated example I was writing triggered an assert!

To be clear, we're still getting most of the perf benefit from #1317 - we're still caching the bbox. Now we have to compute it 1 time. Previously we were trying to compute it zero times by re-using the one from the RTree.

== PERF

There was only a small loss from this change, indicating it was probably a bad
idea from the start.

build prepared polygons time:   [4.5677 ms 4.5717 ms 4.5764 ms]
                        change: [+1.1094% +1.2751% +1.4241%] (p = 0.00 < 0.05)
                        Performance has regressed.

relate already prepared polygons
                        time:   [18.889 ms 18.912 ms 18.942 ms]
                        change: [+0.5218% +0.6533% +0.8127%] (p = 0.00 < 0.05)
                        Change within noise threshold.

build and relate prepared polygons
                        time:   [23.598 ms 23.632 ms 23.671 ms]
                        change: [+0.4791% +0.6917% +0.9029%] (p = 0.00 < 0.05)
                        Change within noise threshold.

unprepared polygons/relate unprepared polygons
                        time:   [744.51 ms 749.08 ms 754.49 ms]
                        change: [-1.2051% -0.1460% +0.8681%] (p = 0.80 > 0.05)
                        No change in performance detected.

I recently broke this (in 44816eb, merged yesterday, not released) by
attempting to reuse the bbox from the geometry graph's RTree.

The problem was that the RTree only contains the Geometry's _segments_,
but Point and MultiPoint have no segments - they're zero-dimensional
geometries.

I don't often use `Relate` with zero dimensional geometries, so it's
only luck that an unrelated example I was writing triggered an assert!

== PERF

There was only a small loss from this change, indicating it was probably a bad
idea from the start.

    build prepared polygons time:   [4.5677 ms 4.5717 ms 4.5764 ms]
                            change: [+1.1094% +1.2751% +1.4241%] (p = 0.00 < 0.05)
                            Performance has regressed.

    relate already prepared polygons
                            time:   [18.889 ms 18.912 ms 18.942 ms]
                            change: [+0.5218% +0.6533% +0.8127%] (p = 0.00 < 0.05)
                            Change within noise threshold.

    build and relate prepared polygons
                            time:   [23.598 ms 23.632 ms 23.671 ms]
                            change: [+0.4791% +0.6917% +0.9029%] (p = 0.00 < 0.05)
                            Change within noise threshold.

    unprepared polygons/relate unprepared polygons
                            time:   [744.51 ms 749.08 ms 754.49 ms]
                            change: [-1.2051% -0.1460% +0.8681%] (p = 0.80 > 0.05)
                            No change in performance detected.
debug_assert_eq!(bounding_rect, geometry_graph.geometry().bounding_rect());

geometry_graph.set_tree(Rc::new(r_tree));
let bounding_rect = geometry_graph.geometry().bounding_rect();
Copy link
Member Author

Choose a reason for hiding this comment

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

We compute the bounding_rect from scratch, and cache that for use in Relate, rather than try to reuse it from the RTree.

};
// They should be equal - but we can save the computation in the `--release` case
// by using the bounding_rect from the RTree
debug_assert_eq!(bounding_rect, geometry_graph.geometry().bounding_rect());
Copy link
Member Author

Choose a reason for hiding this comment

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

This is why I love asserts - they protect me from myself.

@michaelkirk michaelkirk added this pull request to the merge queue Mar 5, 2025
Merged via the queue into main with commit 9f2ca6a Mar 5, 2025
18 checks passed
@michaelkirk michaelkirk deleted the mkirk/fix-bounding-rect branch March 5, 2025 19:45
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