Skip to content

Drop repeated tile coordinates from lines and polygons - #198

Open
dirkwa wants to merge 1 commit into
mapbox:mainfrom
dirkwa:perf/dedupe-tile-vertices
Open

dirkwa wants to merge 1 commit into
mapbox:mainfrom
dirkwa:perf/dedupe-tile-vertices

Conversation

@dirkwa

@dirkwa dirkwa commented Oct 28, 2026

Copy link
Copy Markdown

With tolerance: 0, every source vertex is kept. At low zooms, long runs of those vertices round to the same tile coordinate, so a tile holds many copies of one point. addLine now leaves out a projected point that equals the one before it. At tile resolution that loses nothing, and the tiles kept in the index get smaller. The ring is still allocated at its exact size: the points are projected into a reused scratch buffer and then copied.

We use geojson-vt with tolerance: 0 to turn nautical charts (S-57 ENC) into vector tiles, and dense coastlines made the low zooms expensive. On one chart set (17 cells, z9 to z14, 157k features):

peak memory time
5.0.4 3.6 GB 93 s
this branch 3.0 GB 66 s
5.0.4, heap capped to fit 2 GB 1.53 GB 131 s
this branch, same cap 1.22 GB 129 s

The tiles come out with the same features. With the default tolerance, few points repeat after simplification: on us-states, 3 of 105 tiles lose a point, which is the fixture update. npm run bench route shows no change in time or memory.

In the #118 test, the expected ring drops its repeated [0, 0]. A new test covers a dense line collapsing at z0.

Without simplification (tolerance 0) every source vertex is kept, and at
low zooms long runs of them round to the same tile coordinate. Leaving
out a point equal to the one before it loses nothing at tile resolution
and keeps those tiles small.

This branch has not been deployed

No deployments
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