6 months ago
- Async code is designed to handle latency, not just throughput, making applications responsive by ensuring tasks don't block critical threads.
- Different types of performance exist: throughput (completing tasks quickly) and latency (how long until something happens).
- Event loops are common in modern applications, handling user inputs, repaints, and network requests within tight time budgets (e.g., 16ms for UI responsiveness).
- Non-blocking code ensures the event loop isn't blocked, allowing other tasks to proceed while waiting for slow operations.
- Async/await is syntactic sugar for making asynchronous code more readable but doesn't inherently make code non-blocking.
- Threads and processes can be used for concurrency but come with overheads like context-switching costs, resource limitations, and complexity in thread-safe programming.
- Green threads and M:N schedulers (like in Go) offer lightweight concurrency but may not utilize multiple cores effectively.
- Continuation-passing style (CPS) and generators are alternative methods to achieve non-blocking behavior but can complicate code.
- Async/await in languages like Python, Rust, and JavaScript compiles to state machines or generators, balancing readability and performance.
- Processes are heavy but useful for isolation, while threads are lighter but tricky to manage safely.
- OCaml's effects system provides a powerful alternative for concurrency, allowing resumable computations without explicit async/await syntax.
- Choosing the right concurrency tool depends on the use case: threads for CPU-bound tasks, async/await for I/O-bound tasks, and M:N schedulers for simplicity and scalability.