phpcbf slow execution with unfixable comment
Describe the bug I've worked on a Drupal 7 project, and some files were taking 15+ seconds to run phpcbf. After some investigation I've narrowed the issue to a mis-formatted comment that is not fixable by phpcbf.
I've created 2 sample files (~1000 lines) with the same content except for one comment at the beginning of the test-slow.php file. The normal file takes <1sec to complete and the slow ~15sec.
When having phpcbf run on every file save (with vscode) the long execution time prevents the file from being saved causing serious delay in workflow.
Code sample test-normal.php test-slow.php
Custom ruleset Drupal Code Standard
To reproduce Steps to reproduce the behavior:
- Download the test files called
test-normal.phpandtest-slow.php: 1.1curl -O https://gist.githubusercontent.com/alechko/394a97649460929a5347d8149f4e1f86/raw/276543c6864cf7b3af6e407188fd2a2989df0b76/test-normal.php
1.2 curl -O https://gist.githubusercontent.com/alechko/394a97649460929a5347d8149f4e1f86/raw/276543c6864cf7b3af6e407188fd2a2989df0b76/test-slow.php
2. Install Drupal CS
3. Run phpcbf --standard=Drupal test-normal.php and phpcbf --standard=Drupal test-slow.php
phpcbf --standard=Drupal test-normal.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
/Users/alex/dev/php/test-normal.php 1 1052
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------
Time: 886ms; Memory: 20MB
phpcbf --standard=Drupal test-slow.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------
/Users/alex/dev/php/test-slow.php FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------
Time: 15.21 secs; Memory: 22MB
Expected behavior phpcbf execution time should not be delayed because of mis-formatted comment, the comments could be simply ignored.
Versions (please complete the following information):
- OS: MacOS 10.15.7
- PHP: 7.3.11
- PHPCS: 3.5.6
- Standard: Drupal
Note:
phpcs does not have the this issue, if you run phpcs --standard=Drupal on both files the execution time with be almost identical (<1 sec), only phpcbf has this issue.
Source: squizlabs/PHP_CodeSniffer