DRAFT: Cloth off the main thread
1 min readRead The Browser's Main Thread Is Expensive. Want to feel it myself instead of nodding along.
Idea
Verlet cloth. Grid of points, distance constraints, pin the top row, drag with mouse. Their demo is 4,000 loose particles; cloth adds constraint solving, so it should hurt sooner.
Plan
- Naive version: everything in one rAF loop on the main thread. Crank grid size until it janks.
- Measure: frame time, long tasks in the Performance panel.
- Split the solver iterations across frames. Does cloth look wrong when it lags?
- Move sim to a Web Worker, post positions back. Copy vs. transfer vs. SharedArrayBuffer.
- OffscreenCanvas, render in the worker too?
Questions
- How many constraint iterations before it stops looking like rubber?
- Where does the budget actually go — solver, drawing, or GC?
- Is a worker worth it at sizes that fit on a blog page?
TODO: embed the demo, before/after numbers.