Conversation
Eliminated redundant encode-decode cycle in gh_covering by decoding geohashes once and building spatial polygons directly. Before: Grid → encode → gh_to_sf → gh_to_spdf → gh_to_sp → decode → polygons After: Grid → encode → decode → polygons (direct) Performance improvements (100 points, 0.5° spread): - Precision 4: 2.17x faster (10.9ms → 5.0ms) - Precision 5: 2.41x faster (15.9ms → 6.6ms) - Precision 6: 3.13x faster (180.5ms → 57.8ms) - Precision 7: 3.07x faster (5528.6ms → 1802.5ms) Median speedup: ~2.7x across typical use cases All existing tests pass - no breaking changes to API or behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
|
||
| ### PERFORMANCE | ||
|
|
||
| 1. Optimized `gh_covering` by eliminating redundant encode-decode cycle. The function now decodes geohashes once and builds spatial polygons directly, rather than going through `gh_to_sf` → `gh_to_spdf` → `gh_to_sp` → `gh_decode`. Benchmarks show 2-3× speedup across typical use cases, with larger improvements for higher precision values. |
There was a problem hiding this comment.
Do we need to avoid non-ASCII in NEWS?
| 1. Optimized `gh_covering` by eliminating redundant encode-decode cycle. The function now decodes geohashes once and builds spatial polygons directly, rather than going through `gh_to_sf` → `gh_to_spdf` → `gh_to_sp` → `gh_decode`. Benchmarks show 2-3× speedup across typical use cases, with larger improvements for higher precision values. | |
| 1. Optimized `gh_covering` by eliminating redundant encode-decode cycle. The function now decodes geohashes once and builds spatial polygons directly, rather than going through `gh_to_sf` -> `gh_to_spdf` -> `gh_to_sp` -> `gh_decode`. Benchmarks show 2-3x speedup across typical use cases, with larger improvements for higher precision values. |
|
A It seems Claude can basically get the gist of how to use it too even though it's relatively new: https://claude.ai/share/e53b881a-f456-44dc-ae0c-2d96936cf366 |
The minimal covering of a set of points is exactly the set of distinct geohashes containing them. Encode the points directly instead of building and filtering a full bounding-box grid via sp::over. The old grid path scales with bounding-box area: >50k candidate cells at precision 7 and >1.6M at precision 8 for a small box, each materialized as an sp polygon. The fast path scales with the number of points. Output is identical (verified cell-for-cell in tests and benchmark). ~300x faster at precision 7 (200 pts: 3184 ms -> 11 ms); makes precision >=8 point coverings practical. Covers SpatialPoints and SpatialPointsDataFrame; non-point geometries still use the grid + over path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Added a follow-up commit (Phase 3): a fast path for The minimal covering of points is exactly the set of distinct geohashes containing them, so we now encode the points directly instead of building & filtering a full bounding-box grid via ~300× faster at precision 7 (200 pts: 3184 ms → 11 ms) and makes precision ≥8 point coverings practical. Full numbers in |
Summary
This PR optimizes
gh_coveringby eliminating a redundant encode-decode cycle, achieving 2-3× speedup across typical use cases.Problem
The previous implementation had an inefficient data flow:
The encode-decode round-trip was wasteful since we only needed the decoded coordinates to build polygons.
Solution
Streamlined the flow to:
Now
gh_coveringdecodes geohashes once and buildsSpatialPolygonsdirectly, skipping the intermediate conversions throughgh_to_sf→gh_to_spdf→gh_to_sp.Performance Results
Benchmark: 100 random points, 0.5° spread
Median speedup: ~2.7×
Higher precisions show larger absolute time savings (e.g., precision 7 saves ~3.7 seconds).
Testing
✅ All 48 existing tests pass
✅ No breaking changes to API or behavior
✅ Same output as before, just faster
✅ Benchmark scripts included in
benchmarks/Changes
gh_coveringto build polygons directly from decoded coordinatesVerification
Next Steps
This is part of a series of optimization PRs:
🤖 Generated with Claude Code