New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance issue with L.Util.formatNum in Leaflet 1.5 #6668
Comments
cc @inkstak I'm looking at https://leafletjs.com/examples/choropleth/example.html (which is using 1.5.1 as of today), and I can see no noticeable slowdown nor lagginess. Can you publish a fiddle/codepen/plunkr that displays this behaviour? (the lagginess, I mean) While I agree that |
@IvanSanchez it's actually ~99 times slower, according to https://jsperf.com/leaflet-formatnum-performance/1 (for some reason JSperf says it's 99% slower, but look at ops/sec scores) |
Which makes me willing to revert #6587 for the sake of performance |
Hi, sorry for the performance issue. Could we introduce an option to choose the method to round numbers ? |
Hi @inkstak We try to keep Leaflet as simple as possible. Given that this level of precision is not necessary for vast majority of Leaflet users, it would be an overkill to support this functionality in Leaflet core. That being said, you're still able to customize Leaflet to suit your needs. You can even go a step further and publish it a standalone plugin (which can be added to our plugins page). And lastly, thanks for taking your time contributing to Leaflet, it's always greatly appreciated! |
It seems that I misread the jsperf reports here. I must agree with @cherniavskii. |
Just a quick feedback : overwriting is not so easy, due to how Leaflet uses internal API. Almost every Doing the job is not a problem, but maintaining the patch (of the plugin) will be more complicated. |
This commit breaks formatting of numbers that are in scientific notation. This causes errors when trying to use togeojson on countries boarders or features that are near the equator. Causing malformed geojson.
|
The issue is really weird. In sources I see that it is used only when encoding leaflet layers into GeoJSON objects.
I've tried to do this with 1000 polygons: https://jsbin.com/kusigur/edit?js,output |
@johnd0e Leaflet 1.6 doesn't suffer from this performance issue anymore. I haven't looked at what changed, I just upgraded to 1.6 and my application works fine (unlike with 1.5). |
I know. |
@johnd0e Recently I looked into performance issues in our application and found what could have been the cause and that I didn't realize earlier. In my initial post I left out something important: in both the mouseover and mouseout handler, I'm also doing a Now it doesn't change the fact that there was a performance degradation in Leaflet 1.5 that was solved in 1.6, but it was probably exacerbated by the fact that I'm calling Sorry but I don't really have time to produce a code sample, and without React involved in the mix I probably wouldn't be able to reproduce any performance issue. |
@doubliez |
Steps to reproduce
onEachFeature
I add mouseover and mouseout listeners which calllayer.setStyle
in order to highlight the polygons as the user moves their mouse over themIn summary I do something like:
Expected behavior
As the user moves the mouse over the polygons, it smoothly highlights them (by changing fillOpacity) without any lag.
This is the behavior in Leaflet 1.4.
Current behavior
As of Leaflet 1.5, the transition between each polygon is very laggy and user experience is degraded.
Profiling the performance in Chrome, I noticed the culprit is the
formatNum
function.The mouseover and mouseout events used to take about 25ms, now they take about 120ms, and it's clearly noticeable.
Looking at the diff between Leaflet 1.4 and 1.5, I noticed the
formatNum
function indeed has been changed. The related PR is #6587A small benchmark http://jsben.ch/D3VkH shows the performance difference. I suppose the number of times
formatNum
is called is proportional to the number of polygons in my GeoJSON layer, because the performance impact becomes noticeable when more than about 100 polygons are drawn on the map.Environment
Additional context
Minimal example reproducing the issue
I don't have time to produce a minimal example right now, but I can confirm that if I change the code of the
formatNum
function in Leaflet 1.5 to what it was in 1.4, the issue is resolved.The text was updated successfully, but these errors were encountered: