SIGN IN SIGN UP

perf(symbol): claim lowest-index cross-tile match in one pass instead of sorting per query (#7797)

* perf(symbol): claim lowest-index cross-tile match in one pass instead of sorting per query

TileLayerIndex.findMatches runs on the main thread during symbol
placement (every zoom, as tiles are added). On the spatial-index path it
sorted the full candidate set for every symbol on every query. range()
can return many candidates where symbols are coincident (e.g. stacked
point markers), so this per-query Array.sort() became the dominant cost
of placement on dense layers.

Claim the lowest-index unclaimed candidate in a single O(n) pass
instead. This also fixes a latent correctness nit: the previous .sort()
had no comparator, ordering indices lexicographically ([1,2,10] ->
[1,10,2]); the replacement uses the numeric minimum, which is what the
surrounding "first unclaimed parent" logic intends. The one-parent-per-
symbol dedup behaviour (#5993) is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(changelog): reference PR #7797

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor(symbol): address review feedback in findMatches

- Initialize the best-candidate sentinel to Infinity instead of -1,
  simplifying the claim condition (review feedback from @HarelM).
- Split findMatches into findMatchesForIndexedEntry and
  findMatchesForNonIndexedEntry private helpers and move the long
  inline explanations into tsdoc comments (review feedback from
  @HarelM). Behavior is unchanged.

* test(symbol): cover coincident-symbol cross-tile matching

- Add a unit test asserting that coincident symbols sharing one key
  claim the lowest-index unclaimed match in symbol-instance order on
  the KDBush-indexed path (fails under the previous lexicographic
  Array.sort() candidate ordering).
- Add a render test with a dense layer of coincident points (260
  symbols for one text key, above the KDBush indexing threshold) that
  crosses a zoom level and renders mid-fade, guarding the findMatches
  lowest-index claim against label-fade regressions (review feedback
  from @CommanderStorm).

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Harel M <harel.mazor@gmail.com>
Co-authored-by: Frank Elsinga <frank@elsinga.de>
P
pholmstr committed
e06d0c70d0eefcc7af77e5cba8ba12197d0567d1
Parent: 57afeb9
Committed by GitHub <noreply@github.com> on 8/12/2026, 8:16:28 AM