-
Notifications
You must be signed in to change notification settings - Fork 6
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
Improve function performance for an increasing number of stops #31
Comments
I've started work on this issue with a binary search on Searching a hash map |
Initial results:
So performance is slightly slower with 10 stops, but significantly faster with 10000. If the slow-for-10-stops case is a concern, my binary search code could probably use more optimization or we could have a conditional for which search method to apply depending on number of stops. I pushed a profile.js to the tests directory that shows how I'm doing this timing, but please let me know if there is a more appropriate place for that. |
Categorical functions are now in the
So |
@kronick fantastic results! This is a huge improvement. The case of a small number of stops is a concern because most functions in our default styles are like that, but I think we can follow-up with another PR for that. |
I made a quick The benchmarks are as you might expect-- same as the old |
Currently investigating my code as the source of this bug: mapbox/mapbox-gl-js#3838 The first thing I notice is that the following expanded tests fail on input values 680, 681, 682, 690, but not on 7300, 7301, 7302, 7320 (note that I'm exporting
Results are:
It looks like the binary search is returning off-by-one index values sometimes and therefore interpolating between stops lower than it should. This is no good! I'll try to figure out what's wrong with more complete tests. |
As noted by @kronick, evaluation of functions with the regards to the number of stops is more expensive that it could be — we're looping through all stops for each value. Instead:
categorical
functions could use a hash to improve fromO(n)
toO(1)
interval
andexponential
functions can use the fact that stops are supposed to be sorted —using binary search to improve fromO(n)
toO(log N)
. I used a similar trick to optimize feature-filter.The text was updated successfully, but these errors were encountered: