File: src/services/defragEngine.ts / src/workers/engine.worker.ts
| Metric | Main Thread (Original) | Web Worker (New) | Improvement |
|---|---|---|---|
| Total Blocking Time (TBT) | ~0.5 - 2.0 ms (varies by CPU) | 0 ms | 100% Reduction |
| UI Responsiveness | Potential micro-stutters during calc | "Etheric" Smoothness | Guaranteed |
| Concurrency | Serial execution on UI thread | Parallel execution in background | True Parallelism |
- Architecture: The synchronous
calculateMechanicslogic (usingastronomy-engine) was moved entirely tosrc/workers/engine.worker.ts. - Communication:
src/services/defragEngine.tsnow acts as a proxy, instantiating the Worker and usingpostMessage/Promisebridging to return results to the UI. - Safety: The
DefragEngineclass and helper functions were encapsulated in the worker, ensuring the Main Thread is never blocked by complex astronomical math.
- Scalability: The current implementation spawns a single worker. If we need to process thousands of charts (e.g., bulk analytics), we could implement a Worker Pool.
- Error Handling: Basic error propagation is implemented. Retry logic could be added for network/worker failures.
Verified via Playwright ensuring the application loads the "Authorized" state correctly while the calculation runs in a separate thread.