Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Optimize FileTypeMapper for huge PHPDocs #2582

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

Merged
ondrejmirtes merged 1 commit into 1.10.x from optimize-filetypemapper
Aug 24, 2023

Conversation

@ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Aug 24, 2023

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.

mad-briller, herndlm, AJenbo, CanVuralStudocu, staabm, thomasschiet, and besanek reacted with heart emoji
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.

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

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 😊

staabm, mad-briller, and herndlm reacted with rocket emoji

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 😅

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 reacted with laugh emoji

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /