mln_engine/worker/worker_codec/mod.rs
1//! Port-only: tile workers in another wasm instance, through bytes.
2//!
3//! The browser build runs one wasm instance per page or Web Worker, each
4//! with its own memory, so a tile on the map's instance reaches a worker on
5//! another instance only through bytes. A tile's job (`Run`, `tile/job.rs`)
6//! and its reply cross as frames (envelope.rs): a fixed header with the
7//! job's id, then the body, encoded with `mln_wire`. Three things make that
8//! work:
9//!
10//! - Large byte arrays (encoded tiles, decoded images and DEMs, vertex and
11//! index arrays) travel beside a frame's bytes as payloads (`Encoded`,
12//! `mln_wire::payload`), which a host transfers to the other instance
13//! rather than copies.
14//! - What many jobs share crosses once per instance, then by key
15//! (`mln_wire::shared`): source styles, layers, their evaluated
16//! properties and their expressions, and sets of images. A
17//! layout refers back to them (its buckets' binders hold the layers'
18//! expressions, its render data the properties). Expressions cross as
19//! their parsed node trees (`mln_style::wire`), and tile data as
20//! what it is made from (`crate::tile::TileData`); an instance keeps the tile
21//! data of its jobs in a cache of its own, so a later job can name it.
22//! - Trait objects cross as the types they can be (fields.rs): layers'
23//! style data and evaluated properties, and compound expressions, as
24//! their layer type's or function's name, which the reading side resolves
25//! against its own [`Registry`](crate::Registry); buckets as their bucket
26//! type's.
27//!
28//! The payloads, the tables of shared values and the registry reach the
29//! values that need them through the context that each frame is written or
30//! read in (`mln_wire::Context`).
31//!
32//! Glyphs and images stay on the map side: a job gets where they are in the
33//! map's atlas (`Resolved`), never their pixels.
34//!
35//! `MapCodec` (`map_side.rs`) is the map side of one worker instance and
36//! `WorkerCodec` (`worker_side.rs`) that instance's side. `TileWorkerHost`
37//! (host.rs) runs an instance's jobs behind its `WorkerCodec`, and
38//! `RemoteWorkers` (transport.rs) is the map side of the instances, as
39//! `TileWorkers`.
40
41mod envelope;
42pub(crate) mod fields;
43mod host;
44mod map_side;
45mod transport;
46mod worker_side;
47
48pub use envelope::Encoded;
49#[cfg(feature = "bench")]
50pub(crate) use envelope::{read_job_id, read_reply_header};
51pub use host::TileWorkerHost;
52#[cfg(feature = "bench")]
53pub(crate) use map_side::MapCodec;
54pub(crate) use transport::RemoteEvent;
55pub use transport::{RemoteWorkers, ReplySink, ThreadWorkerInstances, WorkerInstances};
56#[cfg(feature = "bench")]
57pub(crate) use worker_side::WorkerCodec;
58
59#[cfg(test)]
60mod tests;