Phase 2: Optimize gh_covering Performance (2-3× Speedup)#44
Open
dshkol wants to merge 2 commits into
Open
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>
This was referenced Nov 11, 2025
|
|
||
| ### 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. |
Owner
There was a problem hiding this comment.
Do we need to avoid non-ASCII in NEWS?
Suggested change
| 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. |
Owner
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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