Commit 651ddcd
authored
perf(boolean-contains): speed up point, line, and MultiPolygon hot paths (#3099)
* perf(boolean-contains): use native MultiPolygon support in Point check
booleanPointInPolygon iterates MultiPolygon members natively, so a
single call replaces one wrapped Polygon call per member - paying the
per-call setup (validation, getCoord, getGeom) once instead of N times
and avoiding the intermediate Polygon object allocations.
Identical semantics: a point strictly inside any member polygon.
* perf(boolean-contains): reduce point-on-line probes in MultiPoint check
isMultiPointOnLine ran the interior probe (ignoreEndVertices: true)
unconditionally for every point, even after an interior point had
already been found, and ran it before the membership check - so points
not on the line paid for both scans before failing.
Check membership first (early exit), and only probe for an interior
point until one is found. Identical semantics.
* perf(boolean-contains): reduce point-on-line probes in LineString check
isLineOnLine ran the interior probe (ignoreEndVertices: true)
unconditionally for every vertex, even after an interior point had
already been found, ran it before the membership check, and wrapped
every coordinate in a fresh Point object although booleanPointOnLine
accepts raw positions.
Check membership first (early exit), only probe for an interior
point (vertex, then segment midpoint) until one is found, and pass
raw coordinates. Identical semantics, including the segment-midpoint
interior detection from #3080.
* perf(boolean-contains): avoid redundant bbox computation in MultiPolygon polygon checks
isPolygonInMultiPolygon and isMultiPolygonInMultiPolygon called
isPolyInPoly once per member polygon, and each call recomputed the
bbox of both geometries - so the candidate polygon's bbox was
recomputed N times for an N-member MultiPolygon.
Let isPolyInPoly accept an optional precomputed bbox for the candidate
polygon and compute it once per candidate in the MultiPolygon loops.
Identical semantics.
An additional whole-MultiPolygon bbox prefilter was tried: it sped up
the fully-outside case by about 50%, but regressed the overlapping-bbox
cases by ~15%, since `calcBbox` over all members is pure added cost
whenever the check passes.1 parent 07aae6f commit 651ddcd
1 file changed
Lines changed: 40 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
113 | 115 | | |
114 | | - | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
136 | 132 | | |
137 | 133 | | |
138 | 134 | | |
| |||
236 | 232 | | |
237 | 233 | | |
238 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
239 | 238 | | |
240 | 239 | | |
241 | 240 | | |
242 | | - | |
| 241 | + | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
293 | | - | |
294 | | - | |
| 292 | + | |
295 | 293 | | |
296 | 294 | | |
297 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
298 | 303 | | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
| 304 | + | |
303 | 305 | | |
304 | 306 | | |
305 | 307 | | |
| |||
325 | 327 | | |
326 | 328 | | |
327 | 329 | | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 330 | + | |
| 331 | + | |
340 | 332 | | |
341 | 333 | | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
356 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
357 | 350 | | |
358 | 351 | | |
359 | 352 | | |
| |||
452 | 445 | | |
453 | 446 | | |
454 | 447 | | |
455 | | - | |
| 448 | + | |
| 449 | + | |
456 | 450 | | |
457 | 451 | | |
458 | 452 | | |
| |||
463 | 457 | | |
464 | 458 | | |
465 | 459 | | |
466 | | - | |
| 460 | + | |
467 | 461 | | |
468 | 462 | | |
469 | 463 | | |
| |||
0 commit comments