Repository navigation
Conversation
Avoids repeated reflection on construction and per-method processing by caching the derived, class-static annotation configuration keyed by static::class. A class's annotations are immutable per process, so the reflection runs once per class (and per class-method) instead of once per instance/call. - $annotationCache: constructor-path config (path, description, requestMethods, authRequired, annotation presence/name). Recorded only after the reflection path (incl. DuplicateMappingException) succeeds. - $methodParamCache: per-(class,method) RequestParam/UseParameterSet descriptors; parameter mutations are replayed per instance with fresh objects (OpenAPI-safe). - $methodAuthCache: per-(class,method) static auth facts only; SecurityContext is always evaluated live, so authorization decisions are never cached. The service name is intentionally NOT cached for unannotated classes, so constructing the same class with different names stays correct. No public API change; behavior (routing, params, auth, OpenAPI docs, fallback name) is preserved. See ADR-0050. Measured (clean A/B, opcache on, Xdebug off, 50k iters, param-heavy service): construction ~12x, manager+6 services ~10x, per-method params ~6x, per-method auth ~5x. Closes #154
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #155 +/- ##
============================================
+ Coverage 93.37% 93.48% +0.11%
- Complexity 1396 1412 +16
============================================
Files 39 39
Lines 3410 3454 +44
============================================
+ Hits 3184 3229 +45
+ Misses 226 225 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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
Caches per-class annotation configuration in
WebServiceso the reflection that derives routing, parameters, and authorization runs once per class per process instead of on every construction and per-method call.Motivation
WebServicere-reflected its attributes (#[RestController],#[GetMapping],#[RequestParam],#[RequiresAuth],#[PreAuthorize],#[UseParameterSet], …) on every construction and on per-method processing. Since a class's annotations are immutable for the process lifetime, this recomputes identical data on a universal hot path — every request constructs at least one service, and aWebServicesManagereagerly constructs all registered services. Closes #154. See ADR-0050.Changes (three
private staticcaches, keyed bystatic::class)$annotationCache— constructor-path config (path, description, requestMethods, authRequired, annotation presence/name). Recorded only after the reflection path — including theDuplicateMappingExceptioncheck — succeeds, so a throwing class never caches a bad state.$methodParamCache— per-(class,method)RequestParam/UseParameterSetdescriptors. Parameter mutations are replayed per instance with fresh objects, so no mutable state is shared (keeps OpenAPI output correct).$methodAuthCache— per-(class,method)static auth facts only (attribute presence +PreAuthorizeexpression string).SecurityContextis always evaluated live, so authorization decisions are never cached.Correctness safeguards
new WebService('users')vsnew WebService('orders')stay independent; only an annotation name is cached, and the final name is resolved per instance.How to Test / Verify
composer test→ 644 tests pass (was 640; +4 newAnnotationCacheTest): cache-miss vs cache-hit produce identical derived state; per-method parameter services yield independent objects across instances; unannotated names stay independent; OpenAPI output is byte-identical across instances.composer fix-csclean.php -n -d opcache.enable_cli=1, Xdebug off, 50k iters, param-heavy service). Ratios are the portable takeaway (absolute µs are machine-specific):WebServiceconstructionconfigureParametersForMethod(fresh instance)checkMethodAuthorization(fresh instance)Breaking Changes and Migration Steps
None. Transparent internal optimization; no API or behavior change.
Checklist
composer fix-cs)SecurityContextevaluated live)Related issues
Closes #154