agentleFS
d-o-hubd-o-hub/do-harness/.agents/skills/tokio-performance/SKILL.md

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

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
  1. Distinctive:

    When writing or reviewing async code, look for these specific anti-patterns:

    line 37

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 TypeExecution ProfileRecommended MechanismRationale & Anti-patterns
Short Bounded CPUIn-memory JSON parsing, small data transformations (<10–100 µs)Execute directly on Tokio worker threadDo NOT offload to spawn_blocking. Thread dispatch overhead outweighs execution time.
Genuinely Blocking / Synchronous I/Ostd::fs file operations, synchronous DB drivers, blocking FFItokio::task::spawn_blocking or dedicated OS thread/poolStalls worker thread if run directly. Offload keeps Tokio executor responsive.
Sustained / Heavy CPUHeavy cryptography, compression, large-scale processing (>1 ms)spawn_blocking, Rayon, or bounded thread poolPrevents worker thread starvation across multi-tenant or concurrent operations.
Latency-Sensitive Network I/OProxy forwarding, HTTP/gRPC requests, stream handlingNon-blocking async futures on worker threads with bounded concurrencyUse 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:

  1. 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.
  2. Unbounded Spawn Fan-out:
    • Violation: Spawning tasks (tokio::spawn) inside an unbounded loop without semaphore or channel backpressure.
    • Fix: Limit concurrency using tokio::sync::Semaphore or bounded channels (e.g. mpsc::channel(buffer)).
  3. Lock-Across-.await:
    • Violation: Holding a synchronous std::sync::MutexGuard or RefCell across an .await boundary.
    • Fix: Drop the guard before awaiting, narrow lock scope, or use tokio::sync::Mutex if holding across yields is unavoidable.
  4. 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.

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 synchronous std::fs file append with mutex locking via tokio::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): Uses spawn_blocking for running sub-processes and walkthrough scripts.
    • Verdict: Already Fine. Legitimate blocking process execution during evaluation runs.

References

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.