squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

PSR12/OpenTag: improve performance #3840

Closed jrfnl closed 9 months ago

jrfnl commented 1 year ago

Description

No functional changes at all, just improving performance of the sniff by changing the order of certain checks.

Some benchmarks for this change run using the Performance report (PR #3810):

Command: phpcs -ps . --extensions=php --ignore=/vendor/ --report=performance --standard=psr12

Output for the PSR12.Files.OpenTag sniff:

Result PHPCS itself Set of Projects A Set of Projects B Set of Projects C
Nr of Files Scanned 614 4115 25546 2250
Before 0.077045 ( 2.3 %) 0.982014 ( 1.9 %) 3.267655 ( 2.1 %) 0.179564 ( 2.1 %)
After 0.000928 ( 0.0 %) 0.013066 ( 0.0 %) 0.091816 ( 0.1 %) 0.109021 ( 1.3 %)

With what the sniff does, the impact is biggest for files/codebases which already comply with the expectations of this sniff.

Suggested changelog entry

PSR12.Files.OpenTag: improved time-to-result for the sniff

Related issues/external references

Fixes #

Types of changes

jrfnl commented 9 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/64