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

Performance problems with internal PHP sniffs #104

Open
FabianKoestring opened this issue Jun 23, 2020 · 8 comments
Open

Performance problems with internal PHP sniffs #104

FabianKoestring opened this issue Jun 23, 2020 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@FabianKoestring
Copy link

Hey there,

on some files we have performance problems with both sniffs (src/WebimpressCodingStandard/Sniffs/PHP/ImportInternalConstantSniff.php and src/WebimpressCodingStandard/Sniffs/PHP/ImportInternalFunctionSniff.php).

Sometimes these sniffs will take up to 20 seconds.

Do you need more data or could this behavior be normal?

@michalbundyra
Copy link
Member

@FabianKoestring

it could be normal for big files - I mean this is what I observed in the past - big file, many internal functions used....

Probably still it is possible to improve the code, so more data could be useful :) Thanks!

@FabianKoestring
Copy link
Author

@FabianKoestring

it could be normal for big files - I mean this is what I observed in the past - big file, many internal functions used....

Probably still it is possible to improve the code, so more data could be useful :) Thanks!

I could provide more information. What do you need?

@michalbundyra
Copy link
Member

@FabianKoestring Example file would be the best. If you can share a file for which the operation is very slow I would be able to xdebug it, check what part is actually slow and try to make it better.

@FabianKoestring
Copy link
Author

Hey @michalbundyra sry for my late reply. I dont want make my private code public so i searched for slow files in some of my vendors. It seems like https://github.com/doctrine/dbal/blob/2.10.x/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php is a relativly big and slow file.

@michalbundyra
Copy link
Member

@FabianKoestring Sorry for late response... I had a quick look on it.
I can confirm, it's fairly slow for big files, but I check also other rules, and it's general issue for big files.
These sniff is even slower as it process all strings in the file, need to recognise namespace, etc.. There is a lot going on.

I cannot see right now any simple fix to improve performance here, and as it is affecting just big files, I am not going to spend more time on it now. Probably from maintenance point of view it would be better to split big files into smaller, if possible.

I am leaving this ticket as open and adding label "help wanted" as maybe someone will be able to investigate it more and provide some improvements.

Thanks for reporting and providing example file.

@michalbundyra michalbundyra added the help wanted Extra attention is needed label Sep 29, 2020
@jrfnl
Copy link

jrfnl commented Mar 5, 2024

@michalbundyra I suspect you can solve most of the performance issues with some of the "trackers"/abstract sniffs I'm working on for PHPCSUtils. Hoping to include those in the 1.1.0 release, though there may already be some utilities available to help mitigate this a little already.

@michalbundyra
Copy link
Member

Thanks, @jrfnl , I'll check it out!

@jrfnl
Copy link

jrfnl commented Mar 5, 2024

@michalbundyra FYI: Part of why the PHPCSUtils utilities are better for performance is that anything which does significant token walking uses an internal cache. This means that if multiple sniffs execute the same functions with the same $stackPtr on the same file under scan, the token walking will only be done once instead of multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants