Skip to content
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

Codesniffer slow when Xdebug is enabled #3337

Open
jansor opened this issue May 9, 2021 · 8 comments · May be fixed by #3724
Open

Codesniffer slow when Xdebug is enabled #3337

jansor opened this issue May 9, 2021 · 8 comments · May be fixed by #3724

Comments

@jansor
Copy link

jansor commented May 9, 2021

I don't know if this is an issue under Code Sniffer or Xdebug, but when i run code sniffers latest version with Xdebug enabled,
if becomes very slow, until even the point that its nor working anymore. i saw in previous comments/ reports that PHPCS is not using xdebug. But never the less when xdebug is toggled its a difference

OS is windows 10 Pro in combination with IIS:
I have upgraded PHP NTS from 8.0.3 to 8.0.6 same behavior
I have tested with xdebug 3.0.3 and also 3.0.4(latest version)

When switching between Code sniffer 3.6.0 and the previous version 3.5.8 its makes a massive difference on execution time, this is when xdebug is enabled.
I have 1435 classes, and files to process and when cache turned off it takes around: Time: 3 mins, 24 secs; Memory: 438MB

But when I run the same set under 3.6.0 then I never been able to finish yet (again when xdebug is enabled).
If I disable xdebug, then 3.6.0 is working fine.

I don't know if someone have the same issue, or can replicate this problem? Again, its possible that the issue is xdebug related, but i only experience it with PHPCS.

PHPCS CLI

php phpcs.phar --standard=PSR12 -d memory_limit=128M --ignore-annotations --no-cache --no-colors --parallel=4 --report=full -p src

Xdebug config from the php.ini file

; XDEBUG may only be loaded on the development servers and are used to get more information regarding exceptions and errors that happen.
[PHP_XDEBUG]
zend_extension = xdebug

; Additional configuration for some of the extensions
[xdebug]
xdebug.mode = develop
xdebug.var_display_max_depth = -1
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1
xdebug.scream = 0
xdebug.force_error_reporting = 1
xdebug.force_display_errors = 1
xdebug.output_dir = "D:\Inetpub\logs\xdebug\"
; Enable profiler to analyses slow pages
;xdebug.mode = profile
xdebug.profiler_output_name = "callgrind.out.%H_%R.%u"
; Enable trace system for memory
; xdebug.mode=trace
xdebug.trace_output_name = "trace.out.%u.%H_%R"

@jrfnl
Copy link
Contributor

jrfnl commented May 9, 2021

In my experience, running any program with Xdebug on is about 3 times as slow as normal as Xdebug gathers and stores information during the run. It's not as bad with Xdebug 3 as it was with Xdebug 2, but to be fair, I wouldn't expect any different when debugging something.

So my question would be: why are you running PHPCS with Xdebug turned on when you are not debugging PHPCS ?

@gsherwood
Copy link
Member

I'm not really sure if there is anything to do here. PHPCS 3.6.0 itself may be marginally slower due to backfilling of a number of new PHP8 features, and maybe this causes a slow-down of xdebug, but I really don't have time to look into this.

If you want to dig into it more, I'd suggest checking a subset of your files and seeing if you can find a specific file that is causing the problem. Maybe something that PHPCS is doing inefficiently could be found from that.

@jansor
Copy link
Author

jansor commented May 10, 2021

I am using xdebug for other projects as well under this configuration inside my CI/CD, sow only disable it for PHPCS would be time consuming.

Maybe its an option to disable xdebug on the fly, as for example PHP Psalm and and PHAN have, cause in the same Run for analyses the code, its working as expected, meaning that xdebug is enabled for Phan and Psalm and they have no effect.

Is their any CLI command i can add to disable the XDEBUG_MODE=off under PHPCS??

I will see i can find some time this week to further check if i can drill down on the files that is causing the issue, but as i assume its not gone be any direct issue with new Rulesets, as i quick tested with only PSR12. in this part its also becoming slow under version 3.6.0 as the same CLI under 3.5.8 does not have the issue

[info] Disabling Xdebug: Phan is around five times as slow when Xdebug is enabled (Xdebug only makes sense when debugging Phan itself)
[info] To run Phan with Xdebug, set the environment variable PHAN_ALLOW_XDEBUG to 1.
[info] To disable this warning, set the environment variable PHAN_DISABLE_XDEBUG_WARN to 1.
[info] To include function signatures of Xdebug, see .phan/internal_stubs/xdebug.phan_php
[debug] Checking PHAN_ALLOW_XDEBUG
[debug] Because xdebug was installed, Phan will restart.
[debug] The Xdebug extension is loaded (3.0.4)
[debug] CTRL signals suppressed
[debug] Process restarting (PHAN_ALLOW_XDEBUG=internal|3.0.4|0|*|*)

@staabm
Copy link

staabm commented Dec 5, 2022

I am also run makeon phpstan-src, which runs phps, phpstan, phpunit in one go.

when xdebug is enabled the phpcs step gets very slow, even with latest xdebug.

there is a composer package which auto-restarts a command when its invoked with xdebug running:
https://github.com/composer/xdebug-handler

Is this something which could be incorporated into phpcs?
Phpstan, composer et. all use it for performance reasons for a pretty long time. It works great

@staabm staabm linked a pull request Dec 5, 2022 that will close this issue
@zlodes
Copy link

zlodes commented Dec 26, 2022

Hi!

Set xdebug.start_with_request to trigger and XDebug won't run when it isn't needed.

@staabm
Copy link

staabm commented Dec 26, 2022

In my experience the process is still a lot slower when xdebug is loaded, even when configured like that

@pimjansen
Copy link

Why not do an opt in for xdebug and just disable it by default using XDEBUG_MODE=off

I do not think there is any usecase to run phpcs with xdebug besides debugging the sniffers itself.

I we di an opt-in it just stays fast for everyone without even worrying about it and if needed it can be enabled when needed

@jrfnl
Copy link
Contributor

jrfnl commented May 25, 2023

Just a heads-up if anyone would be wanting to work on this: as PHPCS 3.x has a minimum PHP version of PHP 5.4, any solution would need to be able to work and be cross-version compatible with Xdebug 2.2 to current (3.2.x at the time of writing)....

Also see:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants