Skip to content

feat(clustering): add SuperClusterAlgorithm for mega-scale marker clustering and configurable badge formatting - #1799

Draft
dkhawk wants to merge 1 commit into
mainfrom
feat/supercluster-algorithm
Draft

dkhawk wants to merge 1 commit into
mainfrom
feat/supercluster-algorithm

Conversation

@dkhawk

@dkhawk dkhawk commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR introduces SuperClusterAlgorithm, a high-performance hierarchical greedy clustering algorithm designed to handle 100,000 to 1,000,000+ markers on Android with sub-millisecond query performance and minimal garbage collection pressure. It also adds configurable cluster badge precision and compact formatting to both DefaultClusterRenderer and DefaultAdvancedMarkersClusterRenderer, alongside an interactive sample demo.

Key Additions & Features

  1. SuperClusterAlgorithm & FlatKdTree:

    • Implements a bottom-up hierarchical zoom pyramid using flat contiguous primitive arrays (DoubleArray, IntArray).
    • Eliminates object allocations (QuadItem, HashSet, HashMap) during runtime pan/zoom, preventing ART GC pauses.
    • Screen-based viewport range queries execute in $O(\log N + K)$ time (< 1 ms across 100k points).
    • Supports incremental location updates, dynamic item additions/removals, and custom cluster radius configuration.
  2. Cluster Renderer Formatting Enhancements:

    • Added maxNonZeroDigits: Int (default: 1) for configurable significant digit precision (e.g., 5, 10+, 50+, 100+, 1k+).
    • Added showExactCount: Boolean (default: false) to display exact item counts only when explicitly requested.
    • Added useCompactNumberFormatting: Boolean and compactUnitUppercase: Boolean for SI notation (k/m vs K/M).
    • Implemented reactive clearIconCache() and forceRecluster invalidation on property mutation.
  3. SuperCluster100kDemoActivity:

    • Demonstrates 100,000 markers clustered around the San Francisco Bay Area.
    • Custom unclustered marker renderer displaying playful gremlins at high zoom levels.
    • Smooth logarithmic color spectrum across cluster sizes (2 to 100,000+ items).
    • Interactive Material cluster settings dialog allowing real-time adjustment of radius, minClusterSize, non-zero digits, and formatting toggles.
  4. Tests & Documentation:

    • Comprehensive unit test suite covering FlatKdTree 2D nearest neighbor queries, zoom pyramid indexing, location updates, invariant proofs, and renderer badge formatting.
    • Performance benchmarks and architectural comparisons in clustering/README.md.

…stering and configurable badge formatting

- Implement SuperClusterAlgorithm with a bottom-up hierarchical zoom pyramid powered by FlatKdTree flat contiguous arrays, enabling sub-millisecond viewport queries on 100k+ markers with minimal GC allocation.
- Support location updates, dynamic item addition/removal, and custom cluster radius configuration.
- Add configurable non-zero digit precision (maxNonZeroDigits), compact SI unit formatting (k/m and K/M), and exact count toggling (showExactCount) to DefaultClusterRenderer and DefaultAdvancedMarkersClusterRenderer with automatic icon cache invalidation.
- Add SuperCluster100kDemoActivity showcasing 100,000 markers in California and 1,000,000 markers across the United States, unclustered gremlin markers, logarithmic color stops, and an interactive cluster settings dialog.
- Add quick dataset switcher with opaque card styling and background coroutine loading indicators.
- Include comprehensive performance benchmarks and architecture documentation in README files.
- Add full unit test coverage validating FlatKdTree, SuperCluster spatial partitioning, location updates, mathematical invariants, and renderer label formatting.
@dkhawk
dkhawk force-pushed the feat/supercluster-algorithm branch from 7441365 to 6d9edd7 Compare September 30, 2026 03:33

This branch has not been deployed

No deployments
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.

1 participant