Remove Reflector from StubFilesExtensionLoader, replace with version checks#486
Conversation
|
I think it would be useful if we could have a phpbench here (similar as in phpstan-src), which makes sure changes in the extension will not regress performance in the future (actually such a benchmark would be useful for all the 1st party extensions). how can the improvement of this change be reproduced? |
17f1a0d to
6562df2
Compare
|
@staabm I have updated the regression test to more closely cover the real use case, which is to avoid BetterReflection initialization just for ResultCache. BetterReflection cache init cost becomes significant only on larger code base. I'm not sure how useful would phpbench be to guard this case - the dummy codebase would need to be big to avoid false positive regression signals. |
| use PHPStan\Command\Output; | ||
| use PHPStan\Testing\PHPStanTestCase; | ||
|
|
||
| final class ResultCacheNoReflectionTest extends PHPStanTestCase |
There was a problem hiding this comment.
thanks for this test.
@ondrejmirtes do you think this one would make sense directly in phpstan-src?
that way we could assert that ResultCache construction will not trigger reflection.
this assumption might be useful as general logic, and is not specific to phpstan-symfony
There was a problem hiding this comment.
based on the test added by @xificurk here, I added one in phpstan-src with phpstan/phpstan-src#5617
I think this is more useful, as we can later on cover all phpstan 1st party extensions with a single test
6562df2 to
27d013e
Compare
|
this got approved by vincent, so I will merge this with the fix-only to verify the newly added phpstan-src test works as expected. thank you @xificurk |
|
Please don't forget to tag the release 😊 |
|
ok cool. I was waiting for a signal that this is fine for you. thanks |
The loader previously used BetterReflection's Reflector to check whether InputBag existed before loading its stubs. This triggered SourceLocator initialization (an expensive cache-populating operation) on every analysis run.
Replace the reflectClass() call with an isInstalledVersionBelow() version check (InputBag was introduced in symfony/http-foundation 5.1). Add a test that wires a ThrowingSourceLocator into the DI container's betterReflectionSourceLocator service, so any future regression that causes getFiles() to touch BetterReflection will fail the test explicitly.
--
Related: