Skip to content

L.LatLngBounds.extend optimization#2380

Closed
fungiboletus wants to merge 3 commits intoLeaflet:masterfrom
SINTEF-9012:master
Closed

L.LatLngBounds.extend optimization#2380
fungiboletus wants to merge 3 commits intoLeaflet:masterfrom
SINTEF-9012:master

Conversation

@fungiboletus
Copy link
Copy Markdown
Contributor

Hello

I'm working on a KD-Tree MarkerCluster and the analysis of performances showed that L.LatLngBounds.extend
was the second most costly operation. So I optimized it, and… the code is less beautiful :(

Anyway, you have this pull-request.

And this is the result, the pull request contains the orange version : (Other is Internet Explorer 11)
2014-01-15 11_21_07-test latlngbounds jsperf JSPerfs

@mourner
Copy link
Copy Markdown
Member

mourner commented Jan 15, 2014

Thanks for the pull! So the main performance win here is calling factories later and 2 times less checks for extending bounds, right?

@fungiboletus
Copy link
Copy Markdown
Contributor Author

Yes, and the removing of Math.max and Math.min has also improved it a bit.

@mourner
Copy link
Copy Markdown
Member

mourner commented Jan 15, 2014

I just remember trying to optimize by removing Math.min/max calls (in some other code) and then coming to conclusion that it makes almost no difference. But maybe I'm wrong. Generally we'd need to find a compromise between performance and simplicity/readability/terseness of the code for this to get into core.

@fungiboletus
Copy link
Copy Markdown
Contributor Author

I updated jperfs page and the Math.min/max version is in green :
2014-01-15 16_48_51-test latlngbounds jsperf - internet explorer

The biggest difference is with Internet Explorer. For the other browsers, it something like 10-15% slower.

Do you want a pull request with the Math.min/max version ?

@ckoppelman
Copy link
Copy Markdown

This is a significant performance pit when using markerclusterer. I'd love this to be pulled into 0.8.

@mourner
Copy link
Copy Markdown
Member

mourner commented Jan 17, 2014

@danzel ^^

@danzel
Copy link
Copy Markdown
Member

danzel commented Jan 20, 2014

Yep, I like this :) We use extend A LOT in MarkerCluster.

@fungiboletus
Copy link
Copy Markdown
Contributor Author

I saw your re-factoring on JsPerf with properties checks instead of instanceof checks. I opted for instanceof because it's faster on iOS7 and equivalent with a desktop computer :-)

@danzel
Copy link
Copy Markdown
Member

danzel commented Jan 20, 2014

Cool, yeah I just wanted to check for myself :)

@mourner
Copy link
Copy Markdown
Member

mourner commented Jan 27, 2014

OK, going to make an attempt at simplifying this a bit soon and then merge.

@ghost ghost assigned mourner Jan 27, 2014
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting back to this pull now... This else block means that the 10 lines of code below will never get executed, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it will, my bad.

@mourner
Copy link
Copy Markdown
Member

mourner commented Feb 27, 2014

OK, managed to simplify the code a bit with 665e766 and merged manually: https://github.com/Leaflet/Leaflet/commits/master

Thanks again, great work!

@mourner mourner closed this Feb 27, 2014
@danzel
Copy link
Copy Markdown
Member

danzel commented Feb 27, 2014

Awesome, next release is going to be intense!

@mourner
Copy link
Copy Markdown
Member

mourner commented Feb 27, 2014

@danzel wanna measure perf improvement in MarkerCluster?

@danzel
Copy link
Copy Markdown
Member

danzel commented Feb 27, 2014

Will do Monday when I'm on a real PC

@fungiboletus
Copy link
Copy Markdown
Contributor Author

Oh, thanks for the merge. I'm happy to know I have 20 lines of code in this wonderful project :-)

@danzel
Copy link
Copy Markdown
Member

danzel commented Mar 4, 2014

Looks like a minor improvement
image

Numbers are the time to cluster 50000 markers.
Top numbers are chrome. Bottom are IE11.
% is the the % time the profiler says is spent in this function (measured separately)

@mourner
Copy link
Copy Markdown
Member

mourner commented Mar 4, 2014

Still a nice improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants