demo · v131
Main thread vs worker: input latency under load
The motivating racing-wheel / MIDI-controller use case: a high-rate input device polled on the main thread suffers when layout/paint runs on the same thread. Move WebHID to a dedicated worker and input latency stays flat regardless of UI load. Drag the synthetic-jank slider.
poll on main thread
old approach
—ms p99
poll in dedicated worker (131)
new approach
—ms p99
the api
// inside worker.js
const devs = await navigator.hid.getDevices();
const dev = devs[0];
await dev.open();
dev.addEventListener("inputreport", (e) => {
// post raw data back, or just process here
postMessage({ ts: performance.now(), data: e.data.buffer });
});