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 FileTypeMapper for huge PHPDocs #2582

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

ondrejmirtes
Copy link
Member

So we parsed the same PHPDoc all over again through $this->phpDocStringResolver->resolve because it's repeatedly needed in $typeMapStack callbacks.

So with these changes, we first go through all the PHPDocs in the file (+ in files of used traits), parse them and save the AST objects to $phpDocNodeMap. This map is then used in $typeMapStack in createNameScopeMap instead of parsing the PHPDocs hundreds of thousands of times again.

The Carbon performance issue is solved with this change.

The disadvantage is that createPhpDocNodeMap has a lot of duplicated code with createNameScopeMap, but I don't know how to make it nice.

We could do a bit more - $this->phpDocStringResolver->resolve is still called in createResolvedPhpDocBlock and in getTypeAliasesMap and at that point we already have PhpDocNode available, but I want to try out how the current version works, and leave this optimization for another day, maybe.

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

@ondrejmirtes ondrejmirtes changed the base branch from 1.11.x to 1.10.x August 24, 2023 21:25
@ondrejmirtes ondrejmirtes merged commit a4fa95a into 1.10.x Aug 24, 2023
410 of 415 checks passed
@ondrejmirtes ondrejmirtes deleted the optimize-filetypemapper branch August 24, 2023 21:30
@mad-briller
Copy link
Contributor

the new version of phpstan is 3x quicker at analyzing one of our packages (1.10.27 => 1.10.32) with an empty result cache

I looked at this problem for so long and got tunnel visioned on the parser itself rather than looking higher level

that is an amazing speed up, really great work @ondrejmirtes

@ondrejmirtes
Copy link
Member Author

Yeah, I'm on the optimization streak right now 😊 In 1.10.x-dev (not yet released) there's one more commit with a speedup 😊

@herndlm
Copy link
Contributor

herndlm commented Aug 25, 2023

Couldn't sleep yesterday because of the heat and a storm. Was checking github, saw your performance commits, couldn't sleep because of excitement about them then 😅

@ondrejmirtes
Copy link
Member Author

@herndlm I'm so sorry 😀 I couldn't sleep and had to finish it because I finally saw what the bottleneck was 😀

@herndlm
Copy link
Contributor

herndlm commented Aug 25, 2023

That's great, I'm currently travelling, so I was only looking at commits :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants