Skip to content

feat(ShapeSource): add addFeatures, updateFeatures and removeFeatures - #4439

Draft
mfazekas wants to merge 4 commits into
mainfrom
feat/shapesource-partial-updates
Draft

mfazekas wants to merge 4 commits into
mainfrom
feat/shapesource-partial-updates

Conversation

@mfazekas

@mfazekas mfazekas commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

Added addFeatures, updateFeatures and removeFeatures ref methods on ShapeSource, as requested in #4234. They call the Mapbox SDK partial GeoJSON updates on iOS and Android, so a small change to a large source doesn't resend the whole shape. The SDK's dataId is not exposed: rnmapbox doesn't surface the event that carries it, and refusal errors report it empty.

There is little on top of the SDK. The features JSON is decoded off the main thread on both platforms. On Android the call then runs on the thread that already applies shape and url changes; on iOS it is applied on main in call order with other partial updates and with shape updates made meanwhile. The promise resolves once the map has the call. The SDK limits are in the JSDoc: features need a unique id or promoteId; a refused id (duplicate add, missing update or remove) stops that call there, keeps the features before it but shows them only with the next accepted change, and reports the id through onMapLoadingError with type source and as a Mapbox error, which development builds show in LogBox; setFeatureState stays the cheaper choice for paint-only changes.

Two ordering gaps are documented, not handled. On Android a call made in the frame a new shape renders in can reach native before the shape mount and is then replaced (3 of 30 tries with the call right after the setState, 0 of 30 one frame later). On iOS a url change doesn't wait for pending calls.

Performance, release builds, 50k points at street zoom, 50 updates of 10 features at 5 Hz, one run per mode (JS ms per update p50, timer lateness p50, process CPU, time for the last update to show):

  1. Android emulator shape: 589 ms, 8.3 s late, 131 s CPU, not caught up after 60 s.
  2. Android emulator partial: 0.3 ms, 17 ms late, 46 s CPU, 39 s to catch up.
  3. Android emulator feature-state: 1.3 ms, 1.1 s late, 6.5 s CPU, 12 ms to catch up.
  4. iOS simulator shape: 87 ms, 17 ms late, 12.2 s CPU, 0.5 s to catch up.
  5. iOS simulator partial: 0.1 ms, 15 ms late, 7.8 s CPU, 0.2 s to catch up.
  6. iOS simulator feature-state: 0.2 ms, 17 ms late, 0.6 s CPU, 0 ms to catch up.

The gain is on the JS thread. On Android the SDK still reprocesses the source for every call, so a sustained stream of calls on a large source falls behind; fewer, larger calls or feature-state keep up. The emulator is noisy: the feature-state lateness was 26 ms in an earlier run. These numbers were measured before the iOS decoding moved off the main thread.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Screenshot OR Video

Checked on an iPhone 17 simulator and an Android emulator with the Partial feature updates example and a release-build harness: numeric and string ids, add, update and remove, refusals in the middle of a call, and calls around a shape change. On Android, a burst of 41 partial calls followed by a new shape now ends on that shape alone in 24 of 24 rounds (it kept 9 to 15 stale features in 3 of 3 before). updateFeatures with 5k, 20k and 50k features resolved in about 240, 430 and 900 ms with main-thread latency p50 under 1 ms during each.

@mfazekas
mfazekas force-pushed the feat/shapesource-partial-updates branch from 4728f03 to d2690bd Compare November 6, 2026 06:35
@mfazekas
mfazekas changed the base branch from main to fix/android-shape-apply-once November 6, 2026 06:35
Base automatically changed from fix/android-shape-apply-once to main November 6, 2026 15:22
Thin ref methods over the Mapbox SDK partial GeoJSON updates on iOS and
Android, with the SDK's optional dataId, so a small change to a large
source doesn't resend the whole shape.
…hape race

A refused id keeps the features before it, but they appear only with the
next accepted change. On Android a call made right after a new shape can
reach the map first and be replaced by it. Checked on an iOS simulator and
an Android emulator.
…thread on iOS

dataId isn't observable from rnmapbox: the SDK event carrying it isn't exposed
and refusal errors report it empty.

iOS decodes the features JSON on a serial background queue and applies the
change on main, keeping order with other partial updates and with shape
updates made while one is pending.
…change

Partial calls decoded their features on the module thread before hopping
to the UI thread, so a shape mount could be queued ahead of them and
features from before that shape survived into it. Hop first and decode
on the source data thread, in order with shape updates.

This branch was previously deployed

1 inactive deployment
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