FileExcluder: Improve performance of isExcludedFromAnalysing#728
Merged
ondrejmirtes merged 2 commits intophpstan:masterfrom Oct 24, 2021
pmmp:file-excluder-performance
Merged
FileExcluder: Improve performance of isExcludedFromAnalysing#728ondrejmirtes merged 2 commits intophpstan:masterfrom pmmp:file-excluder-performance
ondrejmirtes merged 2 commits intophpstan:masterfrom
pmmp:file-excluder-performance
Conversation
I discovered this while debugging #5825. When analysing pmmp/PocketMine-MP@701a71a with a result cache + no unchanged files, I noticed that isExcludedFromAnalysing() took over 9% of the total time spent. I'm not sure why this is needed when result cache is used, but it became immediately obvious to me that there were performance gains to be had here. Before analysis, an xdebug profiler snapshot showed that this method took 9% of the total CPU time and called isFnmatchPattern() over 124,000 times. This is pretty bad considering that PM doesn't use fnmatch patterns at all. isFnmatchPattern() took about 2.7% time. After the patch, this drops to about 1.9% for isExcludedFromAnalysis() and 0.1% for isFnmatchPattern(), with isFnmatchPattern() now being called only ~2,200 times. In real numbers, this shaves off about half a second of pre-analysis time when a result cache is used (at least on Windows).
Member
|
Thank you! |
Contributor
Author
|
I do have another suggestion that cuts it by another 10% or so (in my case), which is to use the literal paths for both keys and values in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I discovered this while debugging phpstan/phpstan#5825.
When analysing pmmp/PocketMine-MP@701a71a with a result cache + no unchanged files, I noticed that isExcludedFromAnalysing() took over 9% of the total time spent. I'm not sure why this is needed when result cache is used, but it became immediately obvious to me that there were performance gains to be had here.
Before analysis, an xdebug profiler snapshot showed that this method took 9% of the total CPU time and called isFnmatchPattern() over 124,000 times. This is pretty bad considering that PM doesn't use fnmatch patterns at all.
isFnmatchPattern() took about 2.7% time.
After the patch, this drops to about 1.9% for isExcludedFromAnalysis() and 0.1% for isFnmatchPattern(), with isFnmatchPattern() now being called only ~2,200 times.
In real numbers, this shaves off a fraction of a second of pre-analysis time when a result cache is used (at least on Windows).