Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize repeated container creation in tests #2860

Conversation

schlndh
Copy link
Contributor

@schlndh schlndh commented Jan 7, 2024

I looked into the performance of creating containers in tests and I found out that creating SourceLocators in ComposerJsonAndInstalledJsonSourceLocatorMaker is by far the most expensive part (on my machine about 1.1s out of 1.4s for the whole uncached getContainer). So here I try to cache it statically for the tests. As far as I can tell, it only depends on a few parameters (at least for now), which seem likely to be the same for most of the tests.

Quick benchmark with rm -rf /tmp/phpstan-tests/; time make tests gives me about 1m 22s with this change vs about 1m 46s without it.

Motivation: This is a preliminary step before I attempt to make it possible for individual test methods to use their own config for the container, instead of just relying on getAdditionalConfigFiles which is static. That would be useful for #2809 and possibly other things as well.

@schlndh schlndh force-pushed the feature-optimizeRepeatedContainerCreation branch from 53b24e2 to fd582fc Compare January 7, 2024 13:10
@ondrejmirtes ondrejmirtes merged commit 5c50118 into phpstan:1.10.x Jan 7, 2024
423 of 424 checks passed
@ondrejmirtes
Copy link
Member

Awesome, thank you!

@schlndh schlndh deleted the feature-optimizeRepeatedContainerCreation branch January 7, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants