Skip to main content

Module worker_codec

Module worker_codec 

Source
Expand description

Port-only: tile workers in another wasm instance, through bytes.

The browser build runs one wasm instance per page or Web Worker, each with its own memory, so a tile on the map’s instance reaches a worker on another instance only through bytes. A tile’s job (Run, tile/job.rs) and its reply cross as frames (envelope.rs): a fixed header with the job’s id, then the body, encoded with mln_wire. Three things make that work:

  • Large byte arrays (encoded tiles, decoded images and DEMs, vertex and index arrays) travel beside a frame’s bytes as payloads (Encoded, mln_wire::payload), which a host transfers to the other instance rather than copies.
  • What many jobs share crosses once per instance, then by key (mln_wire::shared): source styles, layers, their evaluated properties and their expressions, and sets of images. A layout refers back to them (its buckets’ binders hold the layers’ expressions, its render data the properties). Expressions cross as their parsed node trees (mln_style::wire), and tile data as what it is made from (crate::tile::TileData); an instance keeps the tile data of its jobs in a cache of its own, so a later job can name it.
  • Trait objects cross as the types they can be (fields.rs): layers’ style data and evaluated properties, and compound expressions, as their layer type’s or function’s name, which the reading side resolves against its own Registry; buckets as their bucket type’s.

The payloads, the tables of shared values and the registry reach the values that need them through the context that each frame is written or read in (mln_wire::Context).

Glyphs and images stay on the map side: a job gets where they are in the map’s atlas (Resolved), never their pixels.

MapCodec (map_side.rs) is the map side of one worker instance and WorkerCodec (worker_side.rs) that instance’s side. TileWorkerHost (host.rs) runs an instance’s jobs behind its WorkerCodec, and RemoteWorkers (transport.rs) is the map side of the instances, as TileWorkers.

Structs§

Encoded
A frame as it crosses between instances: its bytes, and the byte arrays that travel beside them (mln_wire::payload), which a host can transfer rather than copy.
RemoteWorkers
The map side of tile workers in other worker instances. The renderer given it owns it (Renderer::set_tile_workers), and its instances start then.
ReplySink
Delivers worker instances’ replies, from any thread, to the inbox of the tile store whose RemoteWorkers started them, in the order they were sent. The store hands them to its workers when it takes in what arrived.
ThreadWorkerInstances
Worker instances on threads of this process: a TileWorkerHost on each thread.
TileWorkerHost
What one worker instance runs.

Traits§

WorkerInstances
The worker instances a RemoteWorkers sends its frames to. Their replies come back through the ReplySink the transport gave whoever created them.