perf: 10x dynamic route optimization — handler probe, radix tree#38
Merged
Nadhila-dot merged 2 commits intomainfrom Mar 31, 2026
Merged
perf: 10x dynamic route optimization — handler probe, radix tree#38Nadhila-dot merged 2 commits intomainfrom
Nadhila-dot merged 2 commits intomainfrom
Conversation
added 2 commits
March 31, 2026 13:12
…o-bridge fast-path
Major performance overhaul for parameterized route matching and dispatch:
Router (rsrc/src/router.rs):
- Replace HashMap<MethodKey, _> with [Option<_>; 7] array-indexed dispatch
- Add freeze() to sort radix tree children for binary search (>4 children)
- Iterative match_path for unambiguous trees (no recursion/backtracking)
- SIMD-accelerated segment splitting via memchr
- Stack-allocated param values [&str; 8] instead of Vec
Dispatch pipeline (rsrc/src/lib.rs):
- std::str::from_utf8 instead of from_utf8_lossy for path conversion
- Inline normalize_runtime_path fast-path at call sites
- Single-pass path traversal check (one byte scan vs 4 memmem calls)
- Single-pass header selection with exact capacity pre-computation
- memchr for '?' detection in envelope builders
Handler pre-evaluation (src/index.js):
- probeHandlerForFastPath() calls handler with mock req/res at registration
- Resolves closure variables to literals in synthetic handler source
- Enables Rust dynamic fast-path for handlers like:
res.json({ id: req.params.id, engine: closureVar, mode: 'dynamic' })
- Eliminates Rust→JS→Rust bridge crossing for resolvable handlers
Examples: 01 - Hello World (basic server, createApp, res.json) 02 - Route Params (:param syntax, req.params, multi-param) 03 - HTTP Methods (GET, POST, PUT, PATCH, DELETE, req.json) 04 - Middleware (app.use, path-scoped, next()) 05 - Error Handling (app.error, app.404, custom errors) 06 - CORS (cors middleware, origins, credentials, preflight) 07 - Route Groups (app.group, nested prefixes, API versioning) 08 - Query Params (req.query, multi-value arrays) 09 - Request Body (req.json, req.text, req.body, req.arrayBuffer) 10 - Native Cache (res.ncache, route-level cache option, LRU) 11 - Sessions (session middleware, req.session, HMAC cookies) 12 - Streaming (res.stream, chunked transfer, SSE) 13 - Response Types (res.send, res.type, res.set, res.locals) 14 - Validation (validate middleware, body/params/query schemas) 15 - Optimizations (static/dynamic fast-path, opt, runtime cache) All examples use @http-native/core imports and JSDoc comments.
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.
Major performance overhaul for parameterized route matching and dispatch:
Router (rsrc/src/router.rs):
Dispatch pipeline (rsrc/src/lib.rs):
Handler pre-evaluation (src/index.js):