Repository navigation
v5.2.0: trie router, performance pass, executor hardening - #57
Merged
Merged
Conversation
…ning New dependency-free trie router (lib/router/trie.js): same API, middleware chain, nested routers and error containment as the sequential router with a segment-trie matcher and a compile-on-demand static table. ~80ns static lookups (2x faster than sequential), flat dynamic-route cost at any route count, case-sensitive by default, literal static segments, null-prototype params, no request-keyed cache. Sequential router performance pass: custom find with exact length prefilters (drop-in for Trouter#find), lazy params allocation, top-level lookup fast path, structural query-string fast path, no per-request closure in the setImmediate dispatch. 11-21% faster per lookup at small route tables. Hardening (shared executor, both routers), found by adversarial review: - mount prefixes are stripped from the path only; a query string can no longer become a nested router's path (`/api/acme?x=/admin`) - a user errorHandler is skipped once the response has ended (writing would raise an uncatchable stream error and kill the process) - defaultRoute runs under error containment - one router mounted at several prefixes keeps every mount - use() normalizes g/y RegExp flags like add() - linear query parsing for segment-heavy strings Docs: README, docs/README.md and the landing page promote the trie router. Version bumped to 5.2.0. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
lib/router/trie.js, zero external dependencies): same API, middleware chain, nested routers and error containment as the sequential router, with a segment-trie matcher and a compile-on-demand static table. Case-sensitive by default, literal static segments, null-prototype params, no request-keyed cache. Opt in withrequire('0http/lib/router/trie')().findwith exact length prefilters, lazy params, top-level lookup fast path, structural query-string fast path, no per-request closure in thesetImmediatedispatch.errorHandleris skipped once the response has ended (writing would raise an uncatchable stream error)defaultRouteruns under error containmentuse()normalizes g/y RegExp flagsBenchmarks (ns per lookup, min of 5, Node 22, M2 Pro)
Verification
findvsTrouter#find(millions), query parser vsURLSearchParams(600k strings), all zero diffs🤖 Generated with Claude Code