Repository navigation
perf: round-3 optimizations — dispatch, static, extract, observe hot paths - #31
Merged
Merged
Conversation
…paths Router (C2/C3): split dispatch into a synchronous `route()` head (trie match, param interning, extension insert) plus a single boxed leaf future, removing the double-box at the Tower erasure boundary and the Arc RMW + large state-machine box in `RouterService::call`. Static files: - C7a/b: precompressed `.br`/`.gz` probes are now direct open attempts (one failed open instead of stat+open pairs) for ServeDir and ServeFile; plain files validate through the already-open descriptor, and the canonical serve root is cached in a OnceCell instead of a per-request realpath walk. - C8: embedded serving checks the O(1) `A::get` before the O(assets) directory-prefix scan. - C9: `relative_path` builds one sized string with inline traversal validation; the duplicate PathBuf field is gone. - C10: hot MIME types resolve to 'static header values (table mirrors mime_guess 2.0.5; parity + traversal regression tests added). - C12: fallback services live behind Arc so the per-request service clone is a refcount bump. - C14: hash-derived embedded metadata (ETag/mtime) is cached per asset. Metrics (C11): status/method labels borrowed from canonical 'static forms, route label refcounts the interned Arc, exact-size response bodies record from the size hint without any counting wrapper. Core/extract: C5 replaces per-response HeaderValue::from_str on constant content types with from_static across into_response, response builder helpers, and JSON responses. C15 quick wins: larger JSON serialization hint, `application/json;charset=utf-8` fast path, BufWriter between upload chunks and temp files, targeted multipart boundary extraction (+ tests), cookie-jar memoization shared by all three jar extractors. Gates: cargo fmt --check, clippy --workspace --all-features -all-targets -D warnings, cargo test --workspace --all-features — all green locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Round 3 of the optimization campaign (tracked in the local audit backlog). This PR targets everything outside
arvik-middleware: the dispatch path, static-file serving, extractors, and metrics. Follows #28 (round 2) and #30 (middleware).Router — dispatch unboxing (C2/C3)
RouterService::callused to clone an Arc, box a large async state machine, and re-box again at the erasure boundary. Dispatch is now split into:route()— synchronous: radix-trie match, param interning, extension inserts, returns the leaf future + patternBox::pinat the leaf, with layered and non-layered paths sharing itRemoves one pure-waste heap alloc per request plus two atomic RMWs.
Static files (
arvik-static).br/.gzprobes are now direct open attempts (a miss costs one failed open instead of stat+open pairs) in bothServeDirandServeFile; plain files validate via the already-open descriptor; canonical root cached inOnceCellA::getbefore the O(all-assets) directory-prefix scanrelative_path= one sized String with inline traversal validation (was PathBuf + Vec + N component Strings + join); duplicate field droppedHeaderValue::from_static; table verified byte-for-byte against mime_guess 2.0.5 by unit testArc<BoxCloneService>→ service clone is a refcount bumpNew regression tests: traversal/normalization semantics for
relative_path, content-type table parity vs mime_guess.Metrics (
arvik-observe) — C11StatusCode::as_str()(canonical zero-padded form) — kills the per-requestformat!Arc<str>instead ofto_string()CountingBody, no atomic, no callback allocation for any Content-Length response; only genuinely streamed bodies get wrappedCore / extract
HeaderValue::from_staticacrossinto_response.rs,ResponseBuilderhelpers, and JSON responses (~9 sites) — was malloc+memcpy+validation per responseapplication/json;charset=utf-8fast path before Mime parse;BufWriterbetween upload chunks and temp files; targeted multipart boundary extraction (replaces multer's full Mime parse; quoted/case/first-wins semantics covered by tests); cookie-jar memoization shared across all three jar extractorsH::Futureis a GAT (elimination tracked for the future trait migration)Verification
cargo fmt --all -- --checkRUSTFLAGS="-D warnings" cargo clippy --workspace --all-features --all-targetscargo test --workspace --all-featuresDeferred (intentional)