-
Notifications
You must be signed in to change notification settings - Fork 548
FileAnalyser: Move repetitive work out of hot loop #4758
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,8 +103,9 @@ public function analyseFile( | |
| $this->collectErrors($analysedFiles); | ||
| $parserNodes = $this->parser->parseFile($file); | ||
| $linesToIgnore = $unmatchedLineIgnores = [$file => $this->getLinesToIgnoreFromTokens($parserNodes)]; | ||
| $ignoreErrorExtensions = $this->ignoreErrorExtensionProvider->getExtensions(); | ||
| $temporaryFileErrors = []; | ||
| $nodeCallback = function (Node $node, $scope, int $callbackInvocationNumber) use (&$fileErrors, &$fileCollectedData, &$fileDependencies, &$usedTraitFileDependencies, &$exportedNodes, $file, $ruleRegistry, $collectorRegistry, $outerNodeCallback, $analysedFiles, &$linesToIgnore, &$unmatchedLineIgnores, &$temporaryFileErrors, $parserNodes): void { | ||
| $nodeCallback = function (Node $node, $scope, int $callbackInvocationNumber) use (&$fileErrors, &$fileCollectedData, &$fileDependencies, &$usedTraitFileDependencies, &$exportedNodes, $file, $ruleRegistry, $collectorRegistry, $outerNodeCallback, $analysedFiles, &$linesToIgnore, &$unmatchedLineIgnores, &$temporaryFileErrors, $parserNodes, $ignoreErrorExtensions): void { | ||
| /** @var Scope&NodeCallbackInvoker $scope */ | ||
| if ($node instanceof Node\Stmt\Trait_) { | ||
| foreach (array_keys($linesToIgnore[$file] ?? []) as $lineToIgnore) { | ||
|
|
@@ -171,7 +172,7 @@ public function analyseFile( | |
| $error = $this->ruleErrorTransformer->transform($ruleError, $scope, $parserNodes, $node); | ||
|
|
||
| if ($error->canBeIgnored()) { | ||
| foreach ($this->ignoreErrorExtensionProvider->getExtensions() as $ignoreErrorExtension) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could make sense to move it completely out of the callback and just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot see a measurable improvement, even though this loop callback is invoked 800.000 times |
||
| foreach ($ignoreErrorExtensions as $ignoreErrorExtension) { | ||
| if ($ignoreErrorExtension->shouldIgnore($error, $node, $scope)) { | ||
| continue 2; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method was invoked once for every error found