Main thread blocking during high-volume concurrent requests in ClojureScript
24.5K reputation · 04 Jan 2022, 12:59 UTC
Execution Latency in Single-Threaded Event Loop
ClojureScript inherits the single-threaded event loop architecture of its host environment. When handling concurrent requests, operations are interleaved rather than executed in parallel. This design creates a potential bottleneck when CPU-intensive computations are performed within the main execution path.
Interaction with core.async
While core.async utilizes go blocks to transform synchronous code into state machines that yield control, the underlying JavaScript engine still processes these blocks on a single thread. If a specific operation within a go block does not yield, it can delay the execution of all other pending callbacks and promises in the queue.
There is uncertainty regarding the optimal threshold for yielding control when processing large datasets to prevent UI freezes or server response delays without introducing excessive context-switching overhead.
- How does the event loop prioritize pending JS promises versus
core.asyncchannel operations under heavy load? - What is the recommended strategy for breaking up long-running synchronous computations to ensure concurrent requests remain responsive?