tokio-performance
Skill1 starsChanged 30 days agoMITView on GitHub
Workload-aware Tokio performance rules, task offloading strategy, and async code review flags. Use when writing async Rust code, choosing between worker execution vs spawn_blocking/pools, or reviewing async PRs for latency or blocking bugs. Triggers: "tokio", "async", "spawn_blocking", "performance", "concurrency", "lock-across-await".
1 other project uses a version of this.
Adopted by
Most recently taken up by
- d-oit/rust-2026-templatetheir own version, first seen Jun 16, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- d-oit/rust-2026-template★ 15same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- codacy-analysis-cliSkill
- codacy-cloud-cliSkill
- codacy-code-reviewSkill
- configure-codacy-cloudSkill
- configure-codacySkill
- crates-io-name-checkSkill
- event-modelerSkill
- fail-closed-proxySkill
- harnessSkill
- htn-plannerSkill
- issue-to-prSkill
- move-only-decompositionSkill
- nested-build-isolationSkill
- npm-github-publishSkill
- pr-triageSkill
- setup-coverageSkill
- skill-creatorSkill
- skill-distillerSkill
- spike-runnerSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 37
When writing or reviewing async code, look for these specific anti-patterns:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Workload-Aware Tokio Guidance
Overview
Async execution must be workload-aware: spawn_blocking is not a magic speedup. Offloading short, bounded CPU work to a blocking thread pool incurs thread context-switch and synchronization overhead that often exceeds the execution time of the work itself.
This skill mirrors the upstream fix in template #336 (rust-2026-template:.agents/skills/tokio-performance/SKILL.md).
Decision Table: Task Offloading Strategy
| Workload Type | Execution Profile | Recommended Mechanism | Rationale & Anti-patterns |
| Short Bounded CPU | In-memory JSON parsing, small data transformations (<10–100 µs) | Execute directly on Tokio worker thread | Do NOT offload to spawn_blocking. Thread dispatch overhead outweighs execution time. |
| Genuinely Blocking / Synchronous I/O | std::fs file operations, synchronous DB drivers, blocking FFI | tokio::task::spawn_blocking or dedicated OS thread/pool | Stalls worker thread if run directly. Offload keeps Tokio executor responsive. |
| Sustained / Heavy CPU | Heavy cryptography, compression, large-scale processing (>1 ms) | spawn_blocking, Rayon, or bounded thread pool | Prevents worker thread starvation across multi-tenant or concurrent operations. |
| Latency-Sensitive Network I/O | Proxy forwarding, HTTP/gRPC requests, stream handling | Non-blocking async futures on worker threads with bounded concurrency | Use tokio::sync::Semaphore or backpressure channels for fan-out. |
Async Code Review Flags
When writing or reviewing async code, look for these specific anti-patterns:
- Cargo-cult
spawn_blocking:- Violation: Wrapping short, bounded CPU operations (e.g., small JSON deserialization, string format) in
spawn_blocking. - Fix: Keep short bounded CPU operations inline on the worker thread.
- Violation: Wrapping short, bounded CPU operations (e.g., small JSON deserialization, string format) in
- Unbounded Spawn Fan-out:
- Violation: Spawning tasks (
tokio::spawn) inside an unbounded loop without semaphore or channel backpressure. - Fix: Limit concurrency using
tokio::sync::Semaphoreor bounded channels (e.g.mpsc::channel(buffer)).
- Violation: Spawning tasks (
- Lock-Across-
.await:- Violation: Holding a synchronous
std::sync::MutexGuardorRefCellacross an.awaitboundary. - Fix: Drop the guard before awaiting, narrow lock scope, or use
tokio::sync::Mutexif holding across yields is unavoidable.
- Violation: Holding a synchronous
- Repeatedly-Ready / Spin Loops:
- Violation: Tight
tokio::select!or yield loops without cancellation checks or backoff that consume 100% CPU. - Fix: Ensure futures yield properly or incorporate timer/backoff mechanisms.
- Violation: Tight
Existing Codebase Async Review
As part of adopting this guidance (template #336 mirror), existing async offloads in the repository were evaluated:
crates/guardian-proxy/src/server.rs(record_audit): Offloads synchronousstd::fsfile append with mutex locking viatokio::task::spawn_blocking.- Verdict: Already Fine. Legitimate synchronous disk I/O offload to prevent stalling the single-threaded/current-thread worker runtime.
crates/do-harness/src/eval/(agent.rs,grading.rs): Usesspawn_blockingfor running sub-processes and walkthrough scripts.- Verdict: Already Fine. Legitimate blocking process execution during evaluation runs.
References
- Upstream template issue:
rust-2026-templateclosed issue #336. - Tokio Documentation: Cpu-bound tasks and blocking code.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

