Phase 3: Optimize Duplicate Detection (1.25-1.76× Speedup)#45
Open
dshkol wants to merge 2 commits into
Open
Conversation
Replaced double-scan approach (anyDuplicated + which(duplicated)) with single-pass (duplicated only) in gh_to_sp, gh_to_spdf.default, and gh_to_spdf.data.frame. Performance improvements: - Small inputs (n=100): 1.68-1.76× faster - Medium inputs (n=1k-10k): 1.37-1.55× faster - Large inputs (n=100k): 1.25-1.48× faster Median speedup: 1.44× across all input sizes and duplicate ratios Better performance with higher duplicate ratios (1.51× at 90% duplicates) 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 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 duplicate detection in GIS conversion functions by replacing a double-scan approach with a single-pass algorithm, achieving 1.25-1.76× speedup depending on input characteristics.
Problem
The previous implementation scanned input twice to detect and remove duplicates:
This double-scan is wasteful since
duplicated()already identifies all duplicates.Solution
Single-pass approach:
Applied to three functions:
gh_to_spgh_to_spdf.defaultgh_to_spdf.data.framePerformance Results
Comprehensive benchmarks across varying:
Summary Statistics
By Duplicate Ratio
Higher duplicate ratios show better relative performance (more work saved).
Testing
✅ All 48 GIS tests pass
✅ No breaking changes to API or behavior
✅ Same output, same warnings, just faster
✅ Benchmark script and plots included
Visualizations
The PR includes:
benchmarks/dedup_speedup.png- Speedup factor across test casesbenchmarks/dedup_absolute.png- Absolute performance comparisonbenchmarks/dedup_benchmark.R- Reproducible benchmark scriptChanges
Verification
Series Progress
🤖 Generated with Claude Code