fix: prevent slow highlight lookups on layers with many features - #659
Open
BRaimbault wants to merge 1 commit into
Open
BRaimbault wants to merge 1 commit into
BRaimbault wants to merge 1 commit into
Conversation
BRaimbault
force-pushed
the
fix/highlight-perfromance
branch
from
July 21, 2026 07:12
784141e to
d7e448a
Compare
|
BRaimbault
marked this pull request as ready for review
July 24, 2026 10:44
BRaimbault
force-pushed
the
fix/highlight-perfromance
branch
from
September 1, 2026 10:40
d7e448a to
de20237
Compare
BRaimbault
force-pushed
the
fix/highlight-perfromance
branch
from
September 4, 2026 08:45
de20237 to
c467fd0
Compare
|
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Description
What
Replaces the linear scan in
Layer#getFeaturesById()with a cachedMapindex (_featuresById), keyed by both the string uid (properties.id) and the numeric id (f.id) used by Feature State. The index is rebuilt lazily, only when_featuresis reassigned (tracked via_featuresIndexSource).Why
getFeaturesById()is called on every hover/select lookup as part of #657's highlight overlay. The oldthis._features.filter(...)scan is O(n) per call, which becomes a visible hover lag on layers with many features. Caching an id → feature map turns each lookup into O(1) after the first build.This also fixes a latent correctness bug:
Clusterreassigns_featuresafter converting polygons to points for clustering, and the old per-call scan could resolve against whichever array reference happened to be current, including a stale pre-conversion one in some call orderings. The new cache is invalidated by reference equality against_features, so it always reflects the arrayClusterlast assigned — covered by the addedCluster.spec.jstest ("Should resolve against the post-polygon-to-point-conversion features, not a stale reference").Key changes
Layer#getFeaturesById(id)now looks up a cachedMapinstead of scanning_features; returns at most one match (aget, not afilter) since ids are unique per Feature State's requirements._featuresById) is rebuilt only when_featuresis reassigned (e.g.setFeatures()), detected via a stored reference (_featuresIndexSource).setFeatures()replaces the array (Layer.spec.js), and resolution against post-conversion features inCluster(Cluster.spec.js).