mapbox / mapbox/mapbox-gl-js

Performance issues when using feature state with promoted string feature ids

Open
#13,315 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

When using Mapbox feature state to handle updating a source with a large number of features quickly, I find that there is a significant performance degradation when using the promoteId source feature to use a non-numeric string identifier, such as a UUID. The performance gets worse the more features get updated feature state, and is particularly noticeable when zooming in and out of the features on the map.

If I swap the source to use generateId, the issue goes away, and feature state performs as efficiently as expected. I suspect the same may be the case if the features had their own numeric ids, as well.

mapbox-gl-js version: 3.7.0

browser: Chrome Version 130.0.6723.70

Steps to Trigger Behavior
  1. Create a map with a GeoJSON FeatureCollection source. Create a unique string identifier in the properties field of each Feature in the collection, and use promoteId on the map source to point to that identifier field. The issue is more noticeable with a large quantity of data.
  2. Add a layer with paint properties that depend on feature state.
  3. Add mousemove hover behavior to update that feature state property.
  4. Hover over several different points and attempt to zoom in and out of the map. Observe the choppy behavior.
  5. (bonus) replace promoteId with generateId on the source and repeat step 4. Observe the smooth behavior.
Link to Demonstration

With promoteId: https://jsfiddle.net/cLav6hbm/4/
With generateId: https://jsfiddle.net/cLav6hbm/3/

Expected Behavior

Smooth panning and zooming on the map.

Actual Behavior

Choppy panning and zooming on the map.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked JSFiddle reproductions and compare the promoteId and generateId cases while profiling feature-state updates during zooming and mouse movement. No repository file or test is named; done means identifying and fixing the cause of the choppy panning and zooming for promoted string identifiers, with equivalent smooth behavior to the generateId case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.