perf(platform): Reduce container lookup overhead in DI resolution#44
Draft
perf(platform): Reduce container lookup overhead in DI resolution#44
Conversation
Eliminate redundant loadProviderForService calls during dependency resolution by adding a single-operation getIfDefined() path that combines has()+get() into one container access. - ArrayContainerAdapter: add getIfDefined() that delegates to the underlying container's optimized method when available. Remove redundant isset guard from get() for optimized containers. - Injector: use getIfDefined() in buildParameterArrayFromContainer when the container supports it, reducing per-parameter lookups from 3 loadProviderForService calls to 1. - CachingClassInspector: add in-memory cache for method signatures (matching existing constructorCache pattern) to avoid repeated serviceCache lookups for invoke() calls. Co-Authored-By: Claude Opus 4.6 <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
getIfDefined()toArrayContainerAdapterthat combineshas()+get()into a single container operation. When the underlying container supportsgetIfDefined, this reduces per-parameter lookups from 3 redundantoffsetExists/offsetGetcalls to 1.issetguard fromget(): When using an optimized container,get()now uses try/catch instead of a redundantisset+$arr[$id]double-access.CachingClassInspectornow caches method signatures in memory (matching the existingconstructorCachepattern), avoiding repeated serviceCache lookups forinvoke()calls within the same request.Context
When
buildParameterArrayFromContainerresolves dependencies, it callshas()thenget()for each constructor parameter. Both triggerArrayAccesson the underlying container, andget()additionally has anissetguard before the actual$arr[$id]access. For containers with JIT provider loading (whereoffsetExists/offsetGettrigger provider resolution), this means 3 redundant resolution calls per parameter on the happy path. This PR reduces it to 1 via the newgetIfDefined()method.Test plan
🤖 Generated with Claude Code