Skip to content

Make the clouds' map and noise in a web worker - #323

Merged
fredj merged 1 commit into
masterfrom
clouds-worker
Nov 19, 2026
Merged

fredj merged 1 commit into
masterfrom
clouds-worker

Conversation

@fredj

@fredj fredj commented Nov 19, 2026

Copy link
Copy Markdown
Member

The clouds' map (about 60 ms per radar map) and their noise volumes (about a third of a second) were made on the page's thread, so the weather demo stalled at each hour change and when the clouds were first turned on. They are now made in a module worker.

  • cloud-work.js: one worker, started at the first call, one call at a time, the pixels transferred back; a call aborted while it waits is dropped. Without Worker (Node, the tests) or if the worker fails to start, the call runs on the page's thread, with a console warning.
  • clouds.js: setting map or nextMap returns at once; the clouds keep the previous map until the new one is made, and drop a map no longer wanted, whichever of the two is set first. The clouds are drawn, and leave the rain under them to Precipitation, once the noise is made.
  • cloud-map.js and cloud-noise.js import nothing: the demos' Cesium is a page global, which a worker does not see (added to AGENTS.md's known cases).
  • README: a Vite app should exclude the package from optimizeDeps, or Vite's pre-bundling leaves the worker out (not verified in an app outside this repository).

Tested: npm test (the worker path with a fake Worker, the fallback, abort, retry after a failure), typecheck, build, build-demos (the worker bundled, 4.3 kB). In the weather demo, measured with long-animation-frame entries: the clouds' scripts take at most 12 ms of a frame while playing 21 hour changes (nextMap 2 to 5 ms, reading the canvas's pixels), 5 to 9 ms when they are turned on; the clouds render as before. Not measured: WeatherMap's own scans of each map, still on the page's thread.

The cloud map (about 60 ms for the 1024 x 768 radar map) and the noise
volumes (about a third of a second) were made on the page's thread, so
the weather demo stalled at each hour change and when the clouds were
first turned on.

They are now made in a module worker, one call at a time, their pixels
transferred back. The clouds keep the previous map until the new one is
made, and a call for a map no longer wanted is aborted, whichever of the
map and the next map is set first; a map or noise that fails is made
again later. The clouds are drawn, and leave the rain under them to
Precipitation, once the noise is made. Without workers, or if the worker
fails to start, the same work runs on the page's thread, with a warning.
cloud-map.js and cloud-noise.js import nothing: the demos' Cesium is a
page global, which a worker does not see.

closes TASK-15
@fredj
fredj marked this pull request as ready for review November 19, 2026 20:32
@fredj
fredj merged commit 3d37d4d into master Nov 19, 2026
1 check passed
@fredj
fredj deleted the clouds-worker branch November 19, 2026 20:32
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