d3-geo-voronoi icon indicating copy to clipboard operation
d3-geo-voronoi copied to clipboard

Faster

Open Fil opened this issue 7 years ago • 4 comments

Ideas for later:

  • change the arrays into typed arrays when possible (edges => edges2, etc) in the delaunay part
  • use spherical trig for rotation & projection (instead of geoRotation+geoStereographic)
  • use spherical trig for checking if a triangle is clockwise or CCW (instead of geoArea!)

Fil avatar Aug 30 '18 16:08 Fil

Another small optimization is using d3.geoStereographicRaw (or inline the definition) instead of d3.geoStereographic.

mbostock avatar Aug 30 '18 20:08 mbostock

Skimming through the code, I also recommend:

  • Using flat arrays for points — e.g. [x, y, x, y, ... instead of [[x, y], [x, y], ....
  • Avoiding array allocations as much as possible. This includes chained array.map and slice. Inspect each occurrence of allocating methods and try to rewrite for less allocations (e.g. collapse chained function-style transformation into a single for loop).

mourner avatar Aug 31 '18 09:08 mourner

https://github.com/Fil/d3-geo-voronoi/commit/4b9aee7f0bfd84cdc962f97e4dc1d2b9e001f926 uses a direct formula for the stereographic

Fil avatar Aug 11 '19 14:08 Fil

A good reference presentation :) https://www.dotconferences.com/2019/12/vladimir-agafonkin-algorithmic-performance-optimization-in-practice

Fil avatar Jan 26 '20 19:01 Fil