isoloop
0.1.1GitHub

Event-loop isolation for JavaScript apps

An open-source TypeScript library that lets you separate your app’s UI from the work behind it. Each part, UI or headless, runs on its own worker or in a shared pool, and is restarted by a supervisor when it fails. Parts can share state through an optional message bus that keeps its records. The UI stays responsive, and a block or a crash stays in its part while the rest of the app keeps running. React, Preact or plain DOM.

See the featuresThe examples: two run live on the page, the dashboards on their own pages

Try it. This is basic, the smallest example, running in this page: four isolates on three event loops. A and B have a worker each; C and D share a pool and read A’s count. Block or crash one, or block the main thread, and watch what keeps running.

A live recording of four isolates

Show the code behind this demo

basic’s setup, without its recording code. A restart needs no code of its own; A catches up by reading its topic from the earliest record it keeps. Type-checked against the published packages.

main.ts

import { createKernel } from '@isoloop/host';
import workers from 'virtual:isoloop/workers';
import list from './topics';
import contractsUrl from './topics?isolate';
import counter from './counter?isolate';
import ticker from './ticker?isolate';
import primes from './primes?isolate';
import messages from './messages?isolate';

const kernel = createKernel({
  contracts: { url: contractsUrl, list },
  workers,
  heartbeat: { killAfterMs: 2_000 }, // a loop busy for 2 s is restarted
});

// A and B: a worker each.
kernel.spawn({
  id: 'A',
  src: counter,
  surface: surfaces.A,
  grants: { publish: ['count.v1'], subscribe: ['count.v1'] },
});
kernel.spawn({ id: 'B', src: ticker, surface: surfaces.B });

// C and D: one pool, so one event loop.
kernel.spawn({
  id: 'C',
  src: primes,
  surface: surfaces.C,
  pool: 'shared',
  grants: { publish: ['primes.v1'], subscribe: ['count.v1'] },
});
kernel.spawn({
  id: 'D',
  src: messages,
  surface: surfaces.D,
  pool: 'shared',
  grants: { publish: ['note.v1'], subscribe: ['count.v1', 'note.v1', 'primes.v1'] },
});

counter.ts

import { defineIsolate } from '@isoloop/runtime';
import { count } from './topics';

export default defineIsolate<HTMLElement>({
  start(ctx) {
    let n = 0;
    const big = document.createElement('div');
    big.textContent = '0';
    const button = document.createElement('button');
    button.textContent = 'Increment';
    button.addEventListener('click', () => {
      n++;
      big.textContent = String(n);
      void ctx.bus.publish(count, { value: n });
    });
    ctx.bus.subscribe(
      count,
      (r) => {
        if (r.value <= n) return;
        n = r.value;
        big.textContent = String(n);
      },
      { from: 'earliest' },
    );
    ctx.root?.append(big, button);
  },
});

topics.ts

import { contracts, topic } from '@isoloop/bus';
import { z } from 'zod';

export const count = topic('count.v1', {
  schema: z.number().int().nonnegative(),
  retention: { kind: 'last-n', n: 100 },
});

export const primes = topic('primes.v1', {
  schema: z.object({ count: z.number().int(), ms: z.number().nonnegative() }),
  retention: { kind: 'last-n', n: 20 },
});

export const note = topic('note.v1', {
  schema: z.string().trim().min(1).max(200),
  retention: { kind: 'last-n', n: 50 },
});

export default contracts(count, primes, note);

basic’s full source

  • A bar is work running on that thread; time moves to the left.
  • Hatched: the thread is stuck, so nothing else on it can run.
  • A line across a track: that isolate was stopped and started again.
  • A hollow tick is a reaction to a record; the line points to who sent it.
  • The demo’s own measurement records aren’t drawn.

Starting basic…

An isolate that crashes more than 3 times within a minute is marked failed, and the kernel stops restarting it.

Open basic on its own page

What it’s for

  • Keeping one part’s load from stalling the rest. e.g. live dashboards on heavy datasets
  • Moving heavy work off the UI’s thread. e.g. parsing, search, simulation
  • Keeping state through a crash or a reload. e.g. alarms, event logs, drafts
  • Containing code you don’t control. e.g. widgets from other teams, AI-generated components
  • Combining parts with different owners. e.g. micro-frontends from several teams
  • Building apps with no server behind them. e.g. data pipelines over public APIs, on a static host

How it works

Your app’s host runs on the page’s main thread. Each isolate runs in a worker, either one of its own or a pool it shares with others. A visual isolate renders with React, Preact or plain DOM in its worker, and the host applies its DOM changes to the page once per frame and sends input back.

Isolates don’t call each other. They publish records to topics and subscribe to them, through a message bus that runs in a worker of its own and keeps each topic’s records for as long as its retention says. A persistent topic is also written to disk, so it survives a reload.

A supervisor watches every worker’s heartbeat. When an isolate’s own code fails, it alone is restarted. When a worker stops responding, or fails in a way no single isolate can be blamed for, the worker is replaced with every isolate in it. It restarts a crashed isolate up to a set number of times, 3 by default, and fails it on the next crash unless it ran for a set time before one of them, 60 s by default; one that runs that long between crashes keeps being restarted. A restarted isolate reads each topic from where its subscription says: only new records, everything retained, or after its last commit.

How it works, part by part

Features

What it gives

The plant dashboard: 72 widgets on 8 machines, built three ways from the same code and data. What each build does when something goes wrong, at plant-v0.3.1.
NativeNative + workersIsoloop matched
One widget blocks for 3 sWhole page stallsWhole page stallsIts pool stalls; data keeps flowing
With a pool per machine (split, opt-in)——Only that machine’s 8 widgets stall
After the blockNothing restartsNothing restartsThe pool restarts and catches up
A widget throwsDown until reloadDown until reloadRestarted
Alarms and events after a reloadSaved at most once a secondSaved at most once a secondEvery acknowledged record

Every build and placement, with sources

What it costs, and where it helps

The plant dashboard, built natively with workers and with Isoloop in the dashboard’s default placement, matched. Chromium at 5 kHz, medians of 5 interleaved rounds.

Measured on plant-bench at @isoloop/*@0.1.0, 24 November 2026, on 4 cores fixed at 2.0 GHz.

Where it helps

Main thread busyLower is better.
  1. Native + workers78%
    Isoloop matched24%

    54 points lower, better

Typing, medianLower is better.
  1. Native + workers58 ms
    Isoloop matched41 ms

    18 ms lower, within the spread

What it costs

CPU, all threadsLower is better.
  1. Native + workers97%
    Isoloop matched112%

    19 points higher, worse

Memory after GCLower is better.
  1. Native + workers227 MB
    Isoloop matched272 MB

    46 MB higher, worse

  • Native + workers
  • Isoloop matched, better
  • Isoloop matched, worse
  • Each difference is the median of the differences measured in each round, so it can differ from the difference of the two medians.
  • The native builds keep their data in a small store written for this app, with no message bus. They don’t contain a blocked widget, restart a crashed one, replay data to it, check grants or schemas, or keep acknowledged history. The extra CPU and memory pay for those features.

Every figure, at both rates and in every engine, with the method

What Isoloop can’t hide

  • Synchronous layout reads (getBoundingClientRect, offsetWidth) and synchronous focus and scroll. An isolate asks the host and gets a promise back.
  • Third-party code that reaches for window, document.body or localStorage. An isolate gets a DOM subset sized to what Preact and React use.
  • Drag and drop, text selection and canvas drawing tied to pointer timing. Canvas isolates can draw to an OffscreenCanvas instead.
  • Timing every callback. Every worker times the timer, animation-frame, microtask and message callbacks of its isolates, to report how busy it is, with or without automatic placement. An empty callback costs 0.2 to 3.6 µs more, depending on the engine, so a worker that runs 10,000 callbacks a second spends up to about 36 ms of each second on it. Promise continuations aren’t timed. Measured on an x64 CPU with 4 cores capped at 2.0 GHz, in Chromium 159, Firefox 159 and WebKit 27.2, on 2026-11-25 (library commit 9912d5b).
  • The cost. Every worker, the bus and the kernel take CPU, memory and start-up time, as the charts above show.

The full list, in the docs

Compared with the alternatives

Other tools move work off the main thread or keep one part of a page from breaking another. Each does part of what Isoloop does, and some do one part better. The marks come from each project’s own docs.

What each one provides, from its own docs.
ToolUI in a workerSupervision and restartA durable bus with replayA security boundary
IsoloopYesYesYesNo
Remote DOMYesNoNoPartial
PartytownPartialNoNoPartial
worker-domYesNoNoPartial
Comlink + workersNoNoNoNo
Cross-origin iframesNoNoNoYes
scheduler.yield()NoNoNoNo

Every mark with its source, and where each alternative is the better choice

Install

Isoloop runs in the browser.

Isoloop 0.1 is out. On 0.x a minor release may contain breaking changes and a patch doesn’t; the parts marked experimental may change in any minor.

pnpm add @isoloop/host @isoloop/runtime @isoloop/bus
# the topics’ schemas (zod here; any Standard Schema library works):
pnpm add zod
pnpm add -D @isoloop/vite
# for React or Preact isolates:
pnpm add @isoloop/react   # or @isoloop/preact
# for automatic placement (experimental):
pnpm add @isoloop/balancer
# for tools a browser agent can call (experimental):
pnpm add @isoloop/webmcp
# for the devtools panel (experimental):
pnpm add @isoloop/devtools

Getting started

The hosting guide