Performance

From static-web-server/static-web-server · View interactive version

Performance is an AI agent skill from the GitHub repository static-web-server/static-web-server. Measure, optimize, or review performance in the Static Web Server (SWS) project — request hot path, syscalls, allocations, compression cost, caching, thread configuration, binary size, CodSpeed benchmarks, and profiling. Use when a change touches handler.rs, static_files/, fs/, compression, header s

How to use this skill

Skill file

Performance

SWS optimizes for low per-request syscalls and allocations on the static-file path. Changes are justified by a benchmark or profile, not intuition.

When to load: editing the hot path (handler.rs, static_files/, fs/, compression*.rs, control_headers.rs, security_headers.rs, custom_headers.rs, logger/access/, logger/trace_context/body.rs, exts/), adding a bench, reading a CodSpeed result, or adding a dependency.

Workflow

  1. Reproduce and measure with a bench in benches/ or a load test against a release build
  2. Profile to find where time goes
  3. Change one thing, re-measure, keep it only if the gain is measurable
  4. Add or update a bench so CodSpeed catches regressions
  5. Never trade correctness or security for speed. A cached security decision needs a bounded staleness window (containment cache)

What the Hot Path Already Does

Don't undo these:

Hot-Path Rules

Threads and Runtime

Release Build

[profile.release]: lto = "fat", codegen-units = 1, panic = "abort", opt-level = 3, strip = true. Don't propose these as improvements.

Profiling uses the release-profiling profile (debug info, not stripped):

cargo build --profile release-profiling --features all
samply record target/release-profiling/static-web-server -p 8080 -d docker/public/

RUSTFLAGS="-C target-cpu=native" is non-portable; local experiments only.

Benchmarks

Micro-benchmarks (CodSpeed)

benches/ is a standalone crate (codspeed-criterion-compat). Suites: control_headers, static_files, response_headers, http_ext, security_sanitize_path, security_basic_auth, security_redirects. .github/workflows/codspeed.yml runs them per PR in CPU simulation and reports deltas.

cd benches
cargo bench                              # local Criterion timings
cargo bench --bench control_headers

Benches call public functions (control_headers::append_headers, static_files::handle). Expose a thin pub or #[doc(hidden)] pub entry point for a private hot function rather than benchmarking through the server. Register new suites as [[bench]] with harness = false in benches/Cargo.toml.

Load tests

Tools

CPU: samply, perf + flamegraph. Allocations: dhat-rs, Valgrind DHAT. Syscalls: strace -c -f. Type layout: RUSTFLAGS=-Zprint-type-sizes cargo +nightly build --release. Runtime: --metrics (Prometheus), experimental feature for tokio runtime metrics.

Binary Size

About 4MB. Before adding a dependency, build --release --features all before and after and compare. Growth above 100KB needs a feature flag or must replace existing code. default-features = false, enable only what's needed.

Review Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.