Repository navigation
perf(core): cut per-request allocations on the fetch hot path - #75
Merged
Merged
Conversation
Memoize the available-locale list (was rebuilding a Set + sorted array on every request) and invalidate it whenever the i18n map is reassigned. Skip the middleware bind+closure allocation when no middleware is registered, and skip the response-hook pass when none are registered. Benchmark-driven (src/bench/core.bench.ts), Deno 2.8.2, in-process fetch: - core_fetch_api: ~13.3 µs -> ~8-10 µs (p75 13.2 µs -> ~8 µs) - core_fetch_i18n: ~15.4 µs -> ~11-13 µs (p75 15.6 µs -> ~12 µs) https://claude.ai/code/session_015AsggMbqEhejVYtbq1LubN
Merged
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
Benchmark-driven zero-allocation work on the
TenCore.fetchhot path. Profiled the in-process request path with a new micro-benchmark, identified the three biggest per-request allocations, and eliminated them — no public API or behavior change.Changes
_availableLocales— was rebuilding aSet+Object.values()+ sorted array on every request. Now cached in_availableLocalesCache, invalidated wherever_i18nis reassigned (setter,updateManifest, embedded init)._handleRequestwhen no middleware is registered (the common case).Benchmarks (Deno 2.8.2, in-process
fetch)core_fetch_apicore_fetch_i18nRoughly 25–37% faster on the plain API path and 15–30% on the i18n path (p75 is the steadier signal under run-to-run noise).
Verification
tenCore.pipeline.test.tsproves the locale cache invalidates wheni18nis reassigned (404 before config → 200 withContent-Languageafter).core_fetch_api/core_fetch_i18n.deno fmt/deno lint/deno checkclean; full suite green; coverage 90.6% (above the 90% floor).https://claude.ai/code/session_015AsggMbqEhejVYtbq1LubN
Generated by Claude Code