perf(api): compile request controller resolution - #29
Merged
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-01a01745-dd95-747a-957f-c70955e98bc1 Co-authored-by: Upd4ting <upd4ting@gmail.com>
This was referenced Aug 19, 2026
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
Design and scope safety
The registration callback now builds immutable handler resolver plans and caches one mutable controller plan per controller class in a
WeakMap. Request execution only reads those plans. It still creates a fresh controller cache on eachRequestContext, and a controller enters that cache only after its computed properties resolve. No request-derived value is stored in the registration cache.This change is limited to
src/implementations/api/index.ts; middleware and router fast paths are unchanged.Benchmark
Environment: Node 20.9.0, Linux x64, same orb and checkout, HTTP keep-alive,
autocannon, 50 connections. Each scenario received a 3-second warm-up followed by five independent 5-second runs. Values below are run means; dispersion is the coefficient of variation across the five runs. Both revisions reported zero errors/timeouts/non-2xx responses.Server RSS after the complete sequential suite was 92,052 KiB before and 91,364 KiB after (-0.7%). This is only an indicative endpoint measurement, not an allocation profile.
Adonis and Nest/Fastify were not included: neither framework is installed in this repository, and introducing separately configured applications would make this focused before/after comparison less controlled. No cross-framework performance claim is made.
Verification
pnpm test: 125 passingpnpm lint: passes, with the existingsrc/server.ts:209accumulator-spread warningpnpm run build: passesRisks and limits
GetControllerInstancecontract remains async and falls back to one-time metadata compilation when called for a controller without a registered route.Greptile Summary
The PR compiles controller and handler resolution metadata during route registration to reduce per-request work while preserving request-local controller instances.
Confidence Score: 5/5
The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issue identified.
The compiled plans preserve request-local caching and parameter semantics on reachable repository paths, and sequential request dispatch prevents overlapping controller initialization within the same request.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Route registration] --> B[Compile handler plan] B --> C[Compile or update controller plan] B --> D[Compile parameter resolvers] E[Incoming request] --> F[Resolve request-local controller] C --> F F --> G{Controller cached?} G -->|Yes| H[Reuse instance] G -->|No| I[Create instance] I --> J[Resolve computed properties] J --> K[Cache instance in RequestContext] H --> L[Resolve handler parameters] K --> L D --> L L --> M[Invoke controller callback]Reviews (1): Last reviewed commit: "perf(api): compile controller resolution..." | Re-trigger Greptile