demo · v130

Main-thread benchmark

When a WebRTC data channel sees ~1k messages/s and each handler does even a tiny amount of JS, the main thread starts blocking. Chrome 130 lets you transfer the entire channel into a worker, so receive handling never touches the main thread. This page runs both topologies side by side, measures main-thread responsiveness (a live FPS jitter plot you can disturb by mousing over), and reports the long-task delta.

Main-thread handler (legacy)

median frame time: ms
long tasks > 50 ms:
messages processed:

Worker-transferred handler (Chrome 130)

median frame time: ms
long tasks > 50 ms:
messages processed:
idle

live main-thread frame times during benchmark (taller bar = slower frame)


  

the code

// Main thread
const pc = new RTCPeerConnection();
const dc = pc.createDataChannel("media-bus");

const worker = new Worker("./bus.js");
worker.postMessage({ channel: dc }, [dc]);   // ← Chrome 130 transfer

// bus.js
onmessage = (e) => {
  const channel = e.data.channel;
  channel.onmessage = (msg) => {
    /* heavy parse runs HERE, off the main thread */
  };
};

see also