Skip to content
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

Add a collision grid for better performance of high density point/label scenes #722

Merged
merged 1 commit into from
Jun 11, 2019

Conversation

bcamper
Copy link
Member

@bcamper bcamper commented Jun 9, 2019

Previously, the collision system has been brute force for all labels (points and text labels with collision enabled) in the current set of visible tiles. As labels are placed, every new label candidate is tested against every previously placed label.

This brute force approach has been fine (and often faster than adding indexing schemes which bring their own overhead) with typical / small sets of labels, e.g. ~1000. As label density grows, it get quadratically slower, and with large (e.g. 100,000 points) sets it is essentially unusable (multi-second collision passes). These cases have not arisen in typical Tangram basemap scenes, but easily can with dataviz (in many cases you have collision off for these large sets anyway... but you still want a practical way to turn them on for some use cases).

This PR adds a simple collision grid system to drastically reduce the number of collisions performed for dense data sets. In a collision grid, the labels are divided (in this case in screen-space) into a grid of a given size; each label is added to the one or more grid cells that it intersects. When we need to know which labels a given label intersects, we only need to test the "local" labels that are in the same grid cells.

The grid size is adaptive based on the label density of the scene. We find the visible tile with the most labels, and determine a grid size based on that. When the label density is low (currently less than 256 labels in the densest tile), the collision grid is skipped entirely.

Currently, the collision grid is only implemented on the main thread collision pass for all labels. The first collision pass of each tile (on the worker thread) is generally assumed to already be "local" enough to not benefit substantially from a grid, though we could benchmark to see if it is helpful for even denser data sets.

collision grid isn't triggered for most base map scenes, but improves collision performance for dense point sets (e.g. dataviz etc.)
@bcamper bcamper added this to the v0.19.0 milestone Jun 9, 2019
@bcamper bcamper merged commit 0a37f38 into master Jun 11, 2019
@bcamper bcamper deleted the collision-grid branch June 11, 2019 20:53
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.

1 participant