Skip to content

rust.cpu_in_async

Performance High

Detects CPU-intensive operations in async functions that block the tokio runtime.

CPU work in async:

  • Blocks runtime threads — All other tasks stall
  • Destroys concurrency — Async benefits lost
  • Causes timeouts — Other operations delayed
// ❌ Before (blocking async runtime)
async fn process() {
let result = expensive_computation(); // Blocks runtime!
}
// ✅ After (offload to blocking thread)
async fn process() {
let result = tokio::task::spawn_blocking(|| {
expensive_computation()
}).await?;
}
  • Heavy computations in async fns
  • Loops without yield points in async
  • Cryptographic operations in async