Performance issues when using feature state with promoted string feature ids
Nobody has claimed this yet.
- 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
- Create a map with a GeoJSON FeatureCollection source. Create a unique string identifier in the
propertiesfield of each Feature in the collection, and usepromoteIdon the map source to point to that identifier field. The issue is more noticeable with a large quantity of data. - Add a layer with paint properties that depend on feature state.
- Add
mousemovehover behavior to update that feature state property. - Hover over several different points and attempt to zoom in and out of the map. Observe the choppy behavior.
- (bonus) replace
promoteIdwithgenerateIdon 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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