Last active
February 6, 2026 18:40
-
-
Save Narrator/3175e425681d041b5b01fee4c4ee23b5 to your computer and use it in GitHub Desktop.
Granularity in rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Coarse: one connection handles everything sequentially | |
| fn handle_all(requests: Vec<Request>) { | |
| for req in requests { | |
| process(req); // Other threads sit idle | |
| } | |
| } | |
| // Fine: each request is a separate task | |
| for req in requests { | |
| tokio::spawn(async move { | |
| process(req).await; | |
| }); | |
| } | |
| // Overhead: task creation, scheduling, memory per task |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment