Skip to content

optimize repeated container creation in tests#2860

Merged
ondrejmirtes merged 1 commit intophpstan:1.10.xfrom
schlndh:feature-optimizeRepeatedContainerCreation
Jan 7, 2024
Merged

optimize repeated container creation in tests#2860
ondrejmirtes merged 1 commit intophpstan:1.10.xfrom
schlndh:feature-optimizeRepeatedContainerCreation

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
@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

Development

Successfully merging this pull request may close these issues.

2 participants