mapbox / mapbox/mapbox-gl-js

Sharing StyleLayers between WorkerTiles is dangerous

Open
#3,479 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

refactoring :building_construction:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

`StyleLayer`s are shared between `WorkerTile`s, via the worker `StyleLayerIndex`. But `StyleLayer`s contain state consisting of the evaluated result of style properties at a certain zoom level, and `WorkerTile`s may have different zoom levels.

Currently, we avoid any issues that this shared state could cause by carefully calling `StyleLayer#recalculate` at the entry point to every async callback in `WorkerTile`. But this is relatively fragile and error prone, and also requires reevaluation of previously-evaluated properties.

A better solution would be to have each `WorkerTile` call `StyleLayer#recalculate` once for each necessary layer, and store the logical result state independently of any other `WorkerTile`s. This would likely require a significant refactor of the internals of style recalculation (refs #2739, #3044).

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 reading the WorkerTile, StyleLayer, and worker StyleLayerIndex implementations to trace how shared layers and asynchronous callbacks use recalculated state. Compare the related discussions in issues #2739 and #3044, then define completion as each WorkerTile maintaining independent recalculation state without fragile callback-level reevaluation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics, frontend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.