Skip to content
Browser worker resource limits and observability

Browser worker resource limits and observability

Research for Shell-managed client App workers (see root CONTEXT.md).
Question: what do major browsers expose (or enforce) about dedicated/worker memory, CPU, and lifecycle under pressure — and what can a same-origin Shell actually observe or control?

Executive finding

There is no portable Web API for “cap this dedicated worker at N MiB” or “kill when CPU exceeds X.” Browsers treat workers as heavy-weight isolates with implementation-defined heap ceilings; OOM/process pressure can terminate work with only a coarse error (or a dead worker) visible to the owner. A same-origin Shell can terminate() instantly, count live workers, use heartbeats/hang detection it implements itself, and optionally sample memory/CPU pressure via experimental APIs that are gated and incomplete. Soft/hard caps must be Shell policy, not “rely on the browser to be fair among Apps.”


Summary matrix

Concern Spec / platform fact What Shell can do Portability
Concurrent workers HTML: workers are heavy-weight; not for large numbers (HTML Workers) Bound concurrency; LRU kill Portable policy
Per-worker memory cap No standard setter; V8/SpiderMonkey heap limits internal Optional sampling; terminate() on budget Caps = Shell-owned
OOM visibility Engine stops on hard heap limit (V8 heap limit); Chromium process OOM (oom.md) Listen for error; treat silent death as fatal Message often empty / process may die
Memory measurement measureUserAgentSpecificMemory() (COOP/COEP); Chromium performance.memory (non-standard) Periodic estimate if cross-origin isolated Chrome-forward; not Baseline
CPU pressure Compute Pressure PressureObserver (W3C) Observe cpu states if allowed Experimental
Hard kill Worker.terminate() immediate (MDN) Primary control surface Baseline

HTML: workers are expensive; no resource budget API

The HTML Living Standard states workers are relatively heavy-weight, with high start-up and per-instance memory cost, and are not intended to be used in large numbers (e.g. not one worker per pixel) (Workers intro). navigator.hardwareConcurrency returns a hint of logical processors (may be clamped for fingerprinting) — not a worker quota (NavigatorConcurrentHardware).

There is no HTML API to set memory or CPU limits on a Worker. Owner control is create / postMessage / terminate / listen for errors.


Engine heap limits and OOM

V8 / Chromium

V8 enforces a hard heap size limit. On exhaustion it runs last-resort GCs, then stops execution and reports out-of-memory (V8 blog — heap size limit). Chromium dedicated workers start with default heap-limit mode unless debugging raised it (WorkerBackingThreadStartupData::HeapLimitMode::kDefault in Blink’s messaging proxy). Process-level OOM is a major crash class (base::TerminateBecauseOutOfMemory / partition allocator failures) (Chromium OOM docs) — the whole renderer can die, not only one worker with a clean JS exception.

Firefox / SpiderMonkey

Firefox worker runtimes use SpiderMonkey GC settings; source defines WORKER_DEFAULT_RUNTIME_HEAPSIZE as 32 MiB and wires javascript.options.mem.max into JSGC_MAX_BYTES for workers (RuntimeService.cpp). That is an engine default / pref, not a page-controllable Web API. Worker-specific pref overrides were removed (Bug 1743623).

Lesson

Expect asymmetric, opaque ceilings. Do not promise “the browser will soft-throttle App A so App B stays responsive.” The Shell must assume a runaway worker can hurt the tab until terminate() or the process dies.


What the owner Shell can observe

Lifecycle and errors

  • worker.terminate() — immediate stop; worker gets no chance to finish (MDN terminate). Matches the already-locked “Apps must tolerate abrupt kill” contract.
  • error event on Worker — fires when an error occurs in the worker (MDN error event); HTML also defines runtime script error propagation for workers. OOM / abrupt death often yields little actionable detail (empty or generic); treat unexplained error or a non-responsive worker as fatal and rebuild.

Memory APIs

API What it gives Gates / caveats
performance.measureUserAgentSpecificMemory() Promise of estimated bytes + breakdown (can attribute DedicatedWorkerGlobalScope) Secure context + cross-origin isolated; experimental; not Baseline; values not comparable across browsers/versions (MDN; WICG Measure Memory). Exposed on Window / SharedWorker / ServiceWorker; dedicated workers roll up under the window measurement.
performance.memory usedJSHeapSize / limit Chromium-only, non-standard, explicitly unreliable for workers/iframes (MDN).

Privacy intent of Measure Memory: coarse estimates for aggregation, not a precise per-App accounting tool across engines.

CPU / system pressure

Compute Pressure API (PressureObserver) observes quantized pressure states (e.g. cpu) in Window / DedicatedWorker / SharedWorker secure contexts; Permissions Policy compute-pressure; experimental / limited support (W3C Compute Pressure; MDN). Useful as a hint to shed background App workers — not a per-worker CPU meter.

What Shell glue cannot do portably

  • Read another App worker’s precise RSS/CPU counters from the platform.
  • Catch a guaranteed “about to OOM” event on all browsers (V8 DevTools near-OOM pause is for debugging, not production Shell UX).
  • Rely on Firefox/Safari exposing the same memory sampling as Chromium.

Practical concurrency

HTML’s “don’t spawn huge numbers” plus per-isolate baseline cost implies Shell-imposed caps (e.g. max concurrent App workers, tear down non-visible, wake-on-event with hard background cap — already directionally locked on the worker-lifecycle ticket). hardwareConcurrency is only a sizing hint.

Same-origin Shell (personal-cloud v1) simplifies measurement attribution versus multi-origin iframes, but does not remove engine OOM opacity.


Implications for personal-cloud

  1. Shell must implement soft/hard caps (count, visibility, heartbeats, optional memory sampling). Browser fairness is insufficient.
  2. Kill is the real control — terminate() + rebuild; matches termination-tolerant Apps.
  3. Observability is best-effort — COOP/COEP + Measure Memory if the Shell opts into cross-origin isolation; else heartbeats + error events only.
  4. Host remains stricter — server Wasm limits are Host/admin policy with real meters; do not mirror browser vagueness on the Host ticket.
  5. Do not block product design on Measure Memory / Compute Pressure becoming Baseline — treat them as optional enhancers.

Prompts for Host resource grilling (asymmetry)

  • Host: hard memory/CPU/time quotas with kill-without-ask.
  • Client: Shell soft caps + tolerate browser OOM; no promise of precise per-App meters in v1.