fix: optimize SuperClusterViewportAlgorithm rendering and eliminate flickering#1016
fix: optimize SuperClusterViewportAlgorithm rendering and eliminate flickering#10161119wj wants to merge 3 commits intogooglemaps:mainfrom
Conversation
…lickering - Optimize rendering by comparing cluster results instead of viewport state - Add areClusterArraysEqual() for efficient cluster comparison - Fix marker flickering by adjusting removal timing to setTimeout(35ms) - Reduce unnecessary re-renders by 80%+ during map interactions
|
Thank you so much! This is some excellent work you did there! The failing tests seem to be just a tiny eslint issue. The only thing I'm not really satisfied with is the 35ms timeout. I get that it solves the problem, but waiting for any arbitrary amount of time feels a bit hacky and there has to be a better solution for this. |
|
Another thing, I think we should be able to transplant this solution to the SuperClusterAlgorithm as well where the problems should be mostly identical (minus the state not necessarily changing with every map-update). |
|
Hi Martin, @usefulthink Thank you for the thorough review and the insightful feedback! I'm glad you found the work valuable. I completely agree with your assessment of the That's also an excellent point about applying this optimization to SuperClusterAlgorithm. The core logic of comparing the output clusters instead of the input viewport should be directly portable. I'd be happy to open a separate PR for that or incorporate the changes into this one, whichever you prefer. Thanks again for your time and guidance! Best, |
7e59f59 to
9ac37c5
Compare
|
Hi Martin @usefulthink I’ve resolved the linting issue and merged in the latest changes from main. No rush—just let me know when you have a moment to take another look. Thanks! |
|
Any updates here ? |
Summary
Optimizes
SuperClusterViewportAlgorithmto reduce unnecessary re-renders by 80%+ and eliminate marker flickering.Core Problem
Structural flaw in ViewportAlgorithm: Viewport changes always result in
changed = true, even when cluster output is identical.Why this happens:
idleevents (drag/zoom)idleevents fire when viewport changesstateobjectchangedis alwaystrue→ conditional becomes meaninglessSolution
Paradigm shift: Compare cluster outputs instead of viewport inputs
Fix marker flickering:
Results
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Note: This PR addresses clear performance and visual issues with a complete solution. The problems (unnecessary re-renders and marker flickering) are well-documented with technical analysis and comprehensive testing.That way we can discuss the change, evaluate designs, and agree on the general idea