dylanfprice / angular-gm

AngularJS Google Maps Directives
MIT License
198 stars 47 forks source link

Support passing an optional objectId to gmMarkersUpdate to update only the marker associated with that object #92

Closed rognstad closed 6 years ago

rognstad commented 6 years ago

Hi,

I have a map with hundreds-to-thousands of markers in a single gmMarkers directive. I get location updates for individual markers quite frequently--sometimes more than one per second. I had been notifying AngularGM of the update with $scope.$broadcast('gmMarkersUpdate', 'objectsName'), but as the number of markers and frequency of updates increased, CPU usage of the app started to become a problem. I wanted a way to tell AngularGM to update a single marker whose associated object had been changed without having to go through all the markers in the directive.

Here's an attempt to do that. It seems to work well for my needs.

I made Plunkers to demonstrate the before (http://plnkr.co/edit/dnmmcOmeTcpgImONKFOW?p=preview) and after (http://plnkr.co/edit/o7AxQjlfWo4uopcojDBr?p=preview) behavior. Looking at Chrome's task manager, CPU usage seems to be reduced. Here are screenshots Chrome's profiler over 5 seconds of updates: https://imgur.com/a/SB4Dz

I'd appreciate any feedback you have.

Thanks! Matt

dylanfprice commented 6 years ago

Seems reasonable. I'm curious if you have an idea which part of the normal $scope.$broadcast('gmMarkersUpdate', 'objectsName') is slow? It would be interesting to know, it's possible there is something we could easily make faster which would improve perf overall and not just in your specific case.

rognstad commented 6 years ago

Thanks!

I'm not totally sure what is causing the slowness, but profiling my real app suggested that it was the actual draw() calls (e.g. on google.maps.Marker). In my real app, I think it is more expensive than normal since I'm using an OverlayView that has to do a little more work than a standard Marker.

I really appreciate the quick merge!

I'm working on another PR related to per-gmMarkers custom marker constructors. One of these days I'll take another swing at clustering, too. I really didn't like the approach I took over the summer.

dylanfprice commented 6 years ago

Hmm ok good to know on the draw() calls. Thanks for the MR!

On Mon, Nov 27, 2017 at 6:12 PM, Matt Rognstad notifications@github.com wrote:

Thanks!

I'm not totally sure what is causing the slowness, but profiling my real app suggested that it was the actual draw() calls (e.g. on google.maps.Marker). In my real app, I think it is more expensive than normal since I'm using an OverlayView that has to do a little more work than a standard Marker.

I really appreciate the quick merge!

I'm working on another PR related to per-gmMarkers custom marker constructors. One of these days I'll take another swing at clustering, too. I really didn't like the approach I took over the summer.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/dylanfprice/angular-gm/pull/92#issuecomment-347391269, or mute the thread https://github.com/notifications/unsubscribe-auth/AANc_ss1WMbwFlwqoi_7cw7wPlpFVevcks5s62wggaJpZM4QsfOe .