Skip to content

Improve Android clustering performance by batching#1

Merged
elitree merged 2 commits intomainfrom
LF-3815-batch-marker-cluster-android
Feb 1, 2026
Merged

Improve Android clustering performance by batching#1
elitree merged 2 commits intomainfrom
LF-3815-batch-marker-cluster-android

Conversation

@elitree
Copy link
Collaborator

@elitree elitree commented Jan 26, 2026

Based on flutter#10562

Changes Made:

  1. ClusterManagersController.java
 - Added addItems(String clusterManagerId, List<MarkerBuilder> items) method
 - Added removeItems(String clusterManagerId, List<MarkerBuilder> items) method
 - Both methods batch process markers and call cluster() only ONCE after the batch
  1. MarkersController.java
 - Modified addMarkers() to group markers by cluster manager ID before processing
 - Modified removeMarkers() to group markers by cluster manager ID before processing
 - Modified changeMarkers() to also group markers by cluster manager ID before processing
 - All methods now use the new batch operations (addItems/removeItems) when dealing with clustered markers
 - Added necessary imports (ArrayList, Map)
  1. MarkersControllerTest.java
 - Updated test to verify addItems() is called with a list instead of multiple addItem() calls
 - Updated test to verify removeItems() is called with a list instead of multiple removeItem() calls
 - Added new batch operation tests
  1. Documentation
 - Updated CHANGELOG.md with description of the fix
 - Bumped version from 2.18.10 to 2.18.11 in pubspec.yaml

Performance Impact

This fix eliminates the expensive cluster() call that was happening after each individual marker operation. With 2000+ markers, this reduces:

 - Before: 2000+ cluster operations (15-30 second freeze)
 - After: 1 cluster operation per batch (no freeze)

Test Results

✅ All Android unit tests pass (78 tests)
✅ All Dart tests pass (51 tests)
✅ Code formatting passes
✅ Static analysis passes

The implementation is complete and ready for use! This should resolve the performance issues you're experiencing with marker clustering on Android when dealing with large numbers of markers (>2000).

@elitree
Copy link
Collaborator Author

elitree commented Jan 26, 2026

I used copilot to apply the same strategy from the web PR to the android code.

@elitree
Copy link
Collaborator Author

elitree commented Jan 26, 2026

Currently doing some draft testing, and once we have confirmation that this is working will submit an upstream PR.

@elitree elitree merged commit 4f48c62 into main Feb 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant