Skip to content

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

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

mfazekas wants to merge 3 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. Both platforms decode the features JSON off the main thread; on iOS the change is then 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; setFeatureState stays the cheaper choice for paint-only changes. On Android a call made right after a new shape can reach native before that shape and is then replaced by it (3 of 3 tries); this is documented, not handled.

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 a call right after a shape change behaved as described above on both platforms. The latest change (dropping dataId, iOS decoding off the main thread) still needs a device re-check.

@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.

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