FileExcluder: Improve performance of isExcludedFromAnalysing #728
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).