mapbox / mapbox-gl-style-spec

76 stars 38 forks source link

Improve function performance for an increasing number of stops #628

Closed lucaswoj closed 7 years ago

lucaswoj commented 7 years ago

https://github.com/mapbox/mapbox-gl-function/issues/31

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 from O(n) to O(1)
  • interval and exponential functions can use the fact that stops are supposed to be sorted —using binary search to improve from O(n) to O(log N). I used a similar trick to optimize feature-filter.