Skip to content

perf(trace): skip span construction when level is filtered out - #26

Merged
aarambh-darshan merged 1 commit into
mainfrom
perf/trace-layer-fast-path
Aug 23, 2026
Merged

aarambh-darshan merged 1 commit into
mainfrom
perf/trace-layer-fast-path

Conversation

@aarambh-darshan

Copy link
Copy Markdown
Member

Summary

Follow-up to the benchmark report (BENCHMARK_REPORT.md, committed on main via #25): TraceLayer built three Strings plus a format! per request even with no tracing subscriber installed — measured at −50.6% throughput in middleware-heavy deployments.

DefaultMakeSpan::make_span now checks per-level callsite interest via tracing::enabled! and returns Span::none() when the configured level is filtered out. Spans behave exactly as before whenever the level is enabled.

Benchmark (wrk 4t/256c, RUST_LOG=off, laptop loopback)

Metric Before After
Middleware req/s 156,125 218–358k (median ≈218k)
p50 1.31 ms 552 µs
p99 5.48 ms 2.62 ms
Overhead vs bare route −50.6% ≈ −16%

With this gate, arvik's middleware-mode throughput beats actix-web (189k) and axum (124k) — full data in BENCHMARK_REPORT.md §8.

Verification

  • cargo test -p arvik-middleware — 26/26 pass
  • cargo clippy --workspace --all-features -- -D warnings — clean
  • cargo fmt --all -- --check — clean

Closes the optimization target identified in the benchmark analysis.

Benchmark follow-up to BENCHMARK_REPORT.md section 3: TraceLayer built
three Strings plus a version format! per request even when no subscriber
was listening, costing ~51% of throughput under load.

DefaultMakeSpan::make_span now checks per-level callsite interest via
tracing::enabled! and returns Span::none() when the configured level is
filtered out. record() on a disabled span remains a no-op, so handler
behavior is unchanged; spans still appear exactly as before whenever
the level is enabled.

Re-benchmarked (wrk 4t/256c, RUST_LOG=off, laptop loopback):
middleware-mode throughput improved from ~156k to ~218-254k req/s
(median across interleaved rounds), overhead vs bare route dropped from
-50.6% to about -16%, and p99 fell from 5.48ms to 2.62ms. Restores a
clear lead over actix-web (189k) and axum (124k) in the
with-middleware configuration. Full data in BENCHMARK_REPORT.md §8.

Co-Authored-By: Claude <noreply@anthropic.com>
@aarambh-darshan
aarambh-darshan merged commit 351b057 into main Aug 23, 2026
5 checks passed
@aarambh-darshan
aarambh-darshan deleted the perf/trace-layer-fast-path branch August 23, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant