Skip to content

The vector tiles layer held in Rust: style, rules, tasks and restyle on one path for the page and the native app, its API generated - #656

Merged
graffkevin merged 17 commits into
mainfrom
vector-tiles-layer
Dec 5, 2026

Conversation

@graffkevin

Copy link
Copy Markdown
Collaborator

Slice 5, part 4 of the migration (steps 1 to 6): the vector tiles layer held in Rust, its style loaded, its tiles asked for, prepared and restyled through one path on the page and in the native app, its API generated by wasm-facade.

  • Style in Rust (isard-layers::maplibre_style::load, through the Fetch port): the style, its TileJSON and raster sources loaded once for the page and the native app; the TS loader and the native app's hard-coded TileJSON gone. Characterization: crates/domain/layers/data/vector-style-sources.json, recorded from the old TS loader (12 cases).
  • Layer rules in Rust (isard-data::style::layer, maplibre_style::rule): the engine reads the style layers once and evaluates them at each frame's zoom (caps, joins, translations, dashes, opacity by zoom); the page no longer resends eleven arrays every 0.1 zoom. Streets that glow at night found by the streets option's default in Rust. Characterization: vector-layer-rules.json, recorded from the old TS rules (4 styles × 6 zooms).
  • One packed buffer per tile (vector_tiles::packed): one wasm call per tile instead of four, read without a copy; queued tiles installed within UPLOAD_MS, the engine asking for a frame while tiles wait.
  • The Tasks port (isard-system::ports::tasks, native::threads): the engine dispatches the tiles' preparation itself, to the page's workers or native threads, with one task function (vector_tiles::task) for both; the style broadcast once with a version (as MapLibre's setLayers). A task carries input bytes and an affinity key; it has no kind field: one host per kind of task and layer stands for it (a change to the 28 November wording, recorded in target.md).
  • Restyle held by the layer in Rust (vector_tiles::layer): setPaintProperty/setLayoutProperty (JSON values, null back to the default, as MapLibre) decide whether rules, a cut or a restyle task is needed; a tile in flight is restyled on arrival.
  • Generated API: VectorLayer declared in Rust (vector_tiles/api.rs) and generated (TS, React, Python, React Native, web component); the known styles and credits in one data file (crates/domain/layers/data/vector-styles.json).
  • Native app: its vector layer declared as a page's vectors(), its own threads and TileJSON code gone.

API changes (CHANGELOG, Changed): layer.layers → layer.getStyle().layers, layer.tileKeys → layer.getTileKeys(), layer.buildings3d → layer.getBuildings3d(); VectorSublayer and map.addVectorLayer removed; getPaintProperty, getLayoutProperty added; isStreet needs a loaded engine.

The wiring added to the legacy engine (legacy/crates/engine/src/vector_tiles.rs: dispatch, restyle, install) moves to the renderer's frame steps and streaming with step 7 of this part, and to isard-map with slice 8. Step 7 (the tiles' GPU content in the graphic engine) follows in its own PR.

Performance

bun run perf:main on a quiet machine: no path slower. Two one-time costs accepted: a style load ~0.2 ms longer (read in Rust, written back, read by the page; one loader instead of two), the engine's wasm compile and instantiate ~3 ms longer (the style expression compiler linked into the engine; first image unchanged). Rule evaluation per frame: 0.5 µs (Positron) to 4.7 µs (PLAN IGN, 274 layers). Engine wasm 934.8 KB gzip (budget 894 → 973).

example metric main branch diff noise verdict
vector-3d fps 60 60 0 3 within noise
vector-3d frame p95 (ms) 16.8 16.7 -0.1 0.5 within noise
vector-3d worst frame (ms) 17 17 0 17 within noise
vector-3d long tasks 0 0 0 2 within noise
vector-3d long tasks time (ms) 0 0 0 100 within noise
vector-3d heap (MB) 39 39 0 30 within noise
vector-3d draws/frame 631 632 +1 10 within noise
vector-3d main thread (ms/frame) 1.5 1.5 0.0 0.5 within noise
vector-3d frames left alone 0 0 0 5 within noise
vector-night fps 60 60 0 3 within noise
vector-night frame p95 (ms) 16.8 16.7 -0.1 0.5 within noise
vector-night worst frame (ms) 17 17 0 17 within noise
vector-night long tasks 0 0 0 2 within noise
vector-night long tasks time (ms) 0 0 0 100 within noise
vector-night heap (MB) 126 127 +1 30 within noise
vector-night draws/frame 1062 1062 +1 10 within noise
vector-night main thread (ms/frame) 3.5 3.5 0.0 0.5 within noise
vector-night frames left alone 0 0 0 5 within noise
react/vector-3d fps 60 60 0 3 within noise
react/vector-3d frame p95 (ms) 16.7 16.8 +0.1 0.5 within noise
react/vector-3d worst frame (ms) 17 17 0 17 within noise
react/vector-3d long tasks 0 0 0 2 within noise
react/vector-3d long tasks time (ms) 0 0 0 100 within noise
react/vector-3d heap (MB) 40 40 0 30 within noise
react/vector-3d draws/frame 654 654 0 10 within noise
react/vector-3d main thread (ms/frame) 1.5 1.6 +0.1 0.5 within noise
react/vector-3d frames left alone 0 0 0 5 within noise
wind fps 60 60 0 3 within noise
wind frame p95 (ms) 16.8 16.8 0.0 0.5 within noise
wind worst frame (ms) 17 17 0 17 within noise
wind long tasks 0 0 0 2 within noise
wind long tasks time (ms) 0 0 0 100 within noise
wind heap (MB) 15 15 0 30 within noise
wind draws/frame 5 5 0 10 within noise
wind main thread (ms/frame) 0.9 0.8 -0.1 0.5 within noise
wind frames left alone 180 180 0 5 within noise
wind-streets fps 60 60 0 3 within noise
wind-streets frame p95 (ms) 16.8 16.7 -0.1 0.5 within noise
wind-streets worst frame (ms) 17 17 0 17 within noise
wind-streets long tasks 0 0 0 2 within noise
wind-streets long tasks time (ms) 0 0 0 100 within noise
wind-streets heap (MB) 24 24 0 30 within noise
wind-streets draws/frame 464 464 0 10 within noise
wind-streets main thread (ms/frame) 1.4 1.4 0.0 0.5 within noise
wind-streets frames left alone 181 180 -1 5 within noise
wind-streets frames zoomed out 0 20 +20 39 within noise

The style and its vector source's TileJSON are loaded by `isard_layers::maplibre_style::load` through the `Fetch`
port, once for the page (the module function `loadVectorStyle`, reached through `engineBindings()`) and the native
app (`loaded_style`), instead of the SDK's `loadStyle`/`resolveSource`/`fetchTileJson` and the native app's
`TILEJSON`/`tile_template`. Archived sources (`pmtiles://`, `mbtiles://`) are still read by the page through the
`Archives` callback until their slice. Checked against `tests/fixtures/vector-style-sources.json`, recorded on the
TypeScript loader (`maplibre_style_load.rs`); the SDK's tests give `VectorTiles` their own loader.

The style's JSON reader and writer take runs of plain text whole (parse 0.19 -> 0.10 ms, write 0.13 -> 0.05 ms for
Positron, native, under load).
…cript sublayers

tests/fixtures/vector-layer-rules.json: for each style layer vectors() draws in Positron, Liberty, PLAN IGN grey and
the closed network's style, its kind, zoom range, visibility, opacity, patterns and glow, and at six zooms its caps,
joins, miter limit, translation and dashes, as the SDK's sublayer (extracted from vectors() for it) gives them;
recorded by scripts/test/vector-layer-rules-fixture.ts, which leaves with the TypeScript rules.
…step 2; the engine, the SDK and the native app not switched yet)

isard_data::style::layer: LayerRule (kind, zoom range, visibility, opacity, caps, joins, miter limit, translation,
patterns, glow, dashes; the values of the zoom as ZoomCurve) and LayerRule::at, a style layer's values at the
frame's zoom. isard_layers::maplibre_style::rule reads a style layer's JSON into its rule, its expressions sampled at
Expression::zoom_stops (interpolate and step stops, whole zooms between). Checked against
tests/fixtures/vector-layer-rules.json (maplibre_style_rules.rs); the TypeScript sublayer, setVectorSublayers and the
legacy Sublayer still draw.
…ow the frame's zoom, for the page and the native app

The page hands the style layers it draws to the engine as they are (setVectorStyleLayers(id, layersJson, lit)), with
whether the layer shows and is draped (setVectorLayerShown); the engine reads them into LayerRule
(isard_layers::vector_tiles::rules, maplibre_style::rule) and evaluates them at each frame's zoom, so caps, joins,
translations, dashes and a zoom-dependent opacity follow the camera instead of being sent again every tenth of a
level. Which lines glow at night is the engine's (is_street, the default of `streets`); isStreet asks it.

Deleted: setVectorSublayers and its eleven arrays, legacy Sublayer, SublayerArrays and parse (vector_layer.rs, its
translation and range helpers moved to isard_graphic_engine::scene::sublayers), the TypeScript sublayer, dashes,
lineCap, lineJoin, miterLimit, translation, followsZoom, ZOOM_STEP, followZoom, VectorSublayer and the rules
fixture's generator. VectorLayer.layers gives the style layers drawn. The engine's wasm budget raised to 973 KB.
… the frame's budget, for the page and the native app

The basemap worker packs the tile it prepared into one buffer (isard_layers::vector_tiles::packed), the page hands it
over as it is (vectorTileArrived) and the engine installs the tiles waiting right after the frame opens its upload
budget, one at least a frame, a tile whose source bytes were let go asked for again there; the native application's
threads pack theirs and hand them over the same way.

Deleted: the page's upload queue and its UPLOAD_MS, setVectorTileMesh, setVectorTileFeatures, setVectorTilePoints,
the engine API's TileMesh, the worker's per-array layout (preparedVectorTileArrays) and the native MapTarget's mesh,
styles and features methods.
… a restyle restyled once, React Native's methods regenerated
The page draws a frame only when asked: since the vector tiles are installed in the engine's frame, those left in
its queue past the budget waited until something else asked for a frame, and the map could stop with tiles not
drawn (vector-night: buildings and streets missing, labels behind them shown).
… style broadcast once to the workers and the native threads

The engine starts each vector tile's task itself after the frame (isard-system ports::tasks: the page's
basemap workers, native threads), the layer's style broadcast once per version and each task naming its
tile and that version (isard_layers::vector_tiles::task, one function for the workers and the threads).
The source tile's bytes travel inside the packed tile. Removes VectorTileLoader, setVectorTileLoader,
send_vector_tile_work, take_vector_tile_work, hasVectorTileSource, the vectors renderer in the workers,
VectorStyle, VectorTileAt, prepareVectorTile, styleVectorTile and the native application's own threads.

Work in progress: the SDK tests of the vectors layer and of the worker's vectors job still drive the
former loader.
…ir results installed from the next frame, a tile arriving during a restyle restyled once, docs and React Native's methods
… asks of the tiles, their styles evaluated again by tasks of the Tasks port, the page keeping neither its tiles nor their inputs
…its settings and style properties with their getters, its companions behind a class written by hand, a tile in flight during a restyle restyled on arrival

The layer pattern of isard's targets (a class made by another object, without data): VectorsOptions, setFacades/getFacades,
setDrape/getDrape, set/getPaintProperty and set/getLayoutProperty kept by the facade and replayed on a new engine;
VectorLayerCompanionsApi (host) for the draped raster, the 3D buildings and the page's side of the tasks. getStyle(),
getTileKeys(), getBuildings3d() replace layers, tileKeys and the buildings3d field; map.addVectorLayer gone.
…, read by the layers crate and generated as the SDK's constants
…yer: a basemap by name and the style layers its options keep, the layer read from the style, its threads running the workers' steps, the overzoom level once in the engine
…or the layer's style input, companions.ts, the vector fixtures in the layers crate's data, the style layers' anchoring in isard-layers, the READMEs and docs of the vector tiles layer
@graffkevin
graffkevin merged commit 4565282 into main Dec 5, 2026
9 checks passed
@graffkevin
graffkevin deleted the vector-tiles-layer branch December 5, 2026 01:51
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