Coding-standard: Version 5 is significantly slower than previous versions

Created on 22 Feb 2019  路  8Comments  路  Source: slevomat/coding-standard

We've upgraded to version 5 and noticed a massive impact on performance.

By turning on and off the sniffs one by one we managed to track down the problem to the sniffs
ReferenceThrowableOnly, FullyQualifiedGlobalConstants, FullyQualifiedGlobalFunctions and UnusedUses. With these sniffs enabled, the time needed to run all checks increases from 30 seconds to more than 10 minutes, which is impractical.

I've compared the version 4.8.8 against 5.0.0, and there were a lot of changes. Any guess about what may have caused such an impact on performance?

Most helpful comment

I didn't find any obvious problem when running the phpcs with -vv, the processing log is almost identical.

Here are Blackfire profiles for each run of:

vendor/bin/phpcs --standard=all.phpcs.xml --sniffs=SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions

Ran on Windows, PHP 7.3 NTS.

Slevomat CS 4.8.7: https://blackfire.io/profiles/091c61ff-d6eb-482f-b2da-4f08966b3639/graph
Slevomat CS 5.0.0: https://blackfire.io/profiles/fe70c208-dbfe-49c2-bf59-51b5486bbfef/graph

The obvious problem is massive performance hit by calling File::findPrevious().

All 8 comments

Difficult to guess without the code.

I have published a repo, with a single class that reproduces the problem.

Test with all SlevomatCodingStandard rules:

  • Version 4.8.0: 13.88 seconds
  • Version 5.0.0: 41.95 seconds

Test with version 5.0.0, excluding the mentioned rules:

  • ReferenceThrowableOnly: 40.84 seconds
  • FullyQualifiedGlobalConstants: 35.91 seconds
  • FullyQualifiedGlobalFunctions: 37.06 seconds
  • UnusedUses: 34.95 seconds
  • All four rules: 23.79 seconds

I didn't find any obvious problem when running the phpcs with -vv, the processing log is almost identical.

Here are Blackfire profiles for each run of:

vendor/bin/phpcs --standard=all.phpcs.xml --sniffs=SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions

Ran on Windows, PHP 7.3 NTS.

Slevomat CS 4.8.7: https://blackfire.io/profiles/091c61ff-d6eb-482f-b2da-4f08966b3639/graph
Slevomat CS 5.0.0: https://blackfire.io/profiles/fe70c208-dbfe-49c2-bf59-51b5486bbfef/graph

The obvious problem is massive performance hit by calling File::findPrevious().

Hmm, I guess it's caused by https://github.com/slevomat/coding-standard/commit/248bd37cab72cdd383600d165b61378ac655e2c2#diff-fc1ee625359b71f7fe46fd9dc33b8fd6R148

It looks I will have to implement some cache.

Can you please try dev-master?

Way better! This version runs in 16.59 seconds.

We're looking forward to the new release :)

Thank you, @kukulich.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spaceemotion picture spaceemotion  路  4Comments

LukasVitek picture LukasVitek  路  4Comments

carusogabriel picture carusogabriel  路  4Comments

aiphee picture aiphee  路  4Comments

grogy picture grogy  路  5Comments