> do you think you this optimization can apply to the default Leaflet API?
I only tried to avoid calling the most time consuming functions in this
specific example for a better comparison and to see how fast it could
get. So this is rather stripping down unnecessary features for that one
use-case than actually optimizing Leaflet code and thus may only be a
starting point for optimizing Leaflet itself. But I don't want to spend
more time on this right now, so anyone feel free to take this on.
Here's a short description of what I've done:
I added a "console.profile" Statement around
L.TileLayer.GeoJSON#_tilesLoaded to automatically collect CPU profiles
in Chrome for the part that I considered most relevant for the
comparison. In the profile I looked for the most time consuming ("Self")
functions:
(1) L.DomEvent.addListener
in L.Path.L.Path.extend._initEvents (Path.SVG.js)
Disabled Path event registration and therefore interactivity (e.g.
Popups) by setting:
L.Path.options.clickable = false;
(2) L.Util.extend (L.setOptions)
in L.Path.L.Class.extend.setStyle
in L.Path.L.Class.extend.initialize
Worked around using L.setOptions by setting default styles (incl.
application-specific) on svg root element once and simply setting (not
merging) the options property with dynamic styles. The other options
(e.g. clickable) then need to be set individually in initialize. See
"L.Map.include" and "L.Path.include" sections - these are
application-specific and not generally applicable without further work.
(3) L.Mixin.Events.addEventListener
in L.FeatureGroup.L.LayerGroup.extend.addLayer
Disabled FeatureGroup event registration by setting
L.FeatureGroup.EVENTS = '';
(4) "Recalculate Style" in Chrome Timeline
in L.Path.onAdd: this._map._pathRoot.appendChild(this._container);
Minimized by removing the SVG root element from the DOM while adding
elements to it (see L.TileLayer.GeoJSON.prototype._tilesLoaded
interception).
The reason I'm interested in this is that I'm working on the
leaflet-tilelayer-geojson project (still buggy):
http://bl.ocks.org/nrenner/raw/5638517/#5/38.100/-97.822
https://github.com/nrenner/leaflet-tilelayer-vector
And Calvin Metcalf is adding some Web Worker magic:
https://github.com/calvinmetcalf/vector-layers