feat: KDBush worker and spatial index exposure #178
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces worker-based spatial indexing and exposes the index for reuse.
Description
scatterplot.get('spatialIndex')createSpatialIndex(points)scatterplot.draw(newPoints, { spatialIndex })Fixes #174
tl/dr: Exposing and (re)using spatial indices is useful when performance is key as it allows to drastically reduce the draw time by skipping the expensive spatial indexing. For instance, imagine you only want to change the z/w coordinates that are used for defining the point color, opacity, or size. Previously, every time you called
scatterplot.draw(points)would trigger a re-indexing of the x/y point coordinates even though the did not change. Similarly, one could now precompute the spatial index and load it upfront. In both cases,scatterplot.draw(points, { spatialIndex })can be dramatically as the spatial indexing is skipped.Caution: Please be advised that when you pass a spatial index to the draw call, regl-scatterplot assumes the index conforms with the point data. Regl-scatterplot does not actual verify that the two conform! So only use this feature if you know what you're doing!
Example
In the example below you can see how one can reuse the initial spatial index to save redrawing time upon follow up draw calls where only the z/w coordinates change.
In the video you can see that this leads to a roughly 6x performance increase in Firefox when rendering one million points.
Spatial.index.reuse.mp4
Checklist
CHANGELOG.mdupdatedREADME.mdadded or updated