Skip to content

Instantly share code, notes, and snippets.

@Narrator
Last active February 6, 2026 18:40
Show Gist options
  • Select an option

  • Save Narrator/3175e425681d041b5b01fee4c4ee23b5 to your computer and use it in GitHub Desktop.

Select an option

Save Narrator/3175e425681d041b5b01fee4c4ee23b5 to your computer and use it in GitHub Desktop.
Granularity in rust
// 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