perf: cache ReflectionClass calls in isPhpCoreClass#607
Merged
Conversation
Avoid repeated ReflectionClass instantiation for the same FQCN by caching results in a static array. Also skip reflection entirely for classes not loaded in the current process, as they cannot be internal. Reduces ReflectionClass calls from 849 to 148 on arkitect's own codebase (104 files). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #607 +/- ##
=========================================
Coverage 98.32% 98.32%
- Complexity 684 689 +5
=========================================
Files 86 86
Lines 1965 1968 +3
=========================================
+ Hits 1932 1935 +3
Misses 33 33 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Member
micheleorselli
left a comment
There was a problem hiding this comment.
I left one comment on the check condition. Apart from that this seems to me a quick win to improve the current situation so 👍
…PhpCoreClass Extends the "not loaded = not core" fast path to traits and enums, avoiding unnecessary ReflectionClass instantiations for unloaded symbols. Co-Authored-By: Claude Sonnet 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.
Closes #580
Problem
isPhpCoreClass()inClassDescriptionBuildercallsnew ReflectionClass()for every dependency of every analyzed class, with no caching. This was identified in #580 as the source of a measurable performance regression introduced after v0.8.0.On arkitect's own 104-file codebase,
ReflectionClasswas being instantiated 849 times — many of those for the same class names repeated across files, and many more for user-land classes that don't even exist in the current process (triggering exception handling as control flow).Changes
class_exists/interface_exists), it cannot be a PHP internal class — returnfalseimmediately, skippingReflectionClassentirely.class_existsfirst,ReflectionClasswill never throw for the classes that reach it, so exception-as-control-flow is gone.checkIsPhpCoreClass: cache logic and detection logic are now in separate methods.Results
Measured on arkitect's own codebase (104 files):
ReflectionClasscalls🤖 Generated with Claude Code