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

UseImportsTraverser: don't deep traverse #4994

Merged
merged 4 commits into from
Sep 11, 2023
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 11, 2023

closes rectorphp/rector#8194

before in codeigniter4

$ time php vendor/bin/rector process tests --dry-run --clear-cache
 326/326 [============================] 100%

 [OK] Rector is done!

real    1m3.584s
user    0m0.000s
sys     0m0.093s

after

time php vendor/bin/rector process tests --dry-run --clear-cache
 326/326 [============================] 100%

 [OK] Rector is done!

real    0m57.164s
user    0m0.015s
sys     0m0.031s

-> 10 % faster

@@ -77,6 +79,10 @@ private function traverseForType(array $stmts, callable $callable, int $desiredT
$this->processGroupUse($node, $desiredType, $callable);
}

if (!$node instanceof Namespace_) {
Copy link
Member

@samsonasik samsonasik Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are 2 top level node:

  • Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace
  • PhpParser\Node\Stmt\Namespace_

@@ -77,6 +80,10 @@ private function traverseForType(array $stmts, callable $callable, int $desiredT
$this->processGroupUse($node, $desiredType, $callable);
}

if (!$node instanceof Namespace_ && !$node instanceof FileWithoutNamespace) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just use if else if else ?

if ($node instanceof Use_) {
   // ...
} elseif ($node instanceof GroupUse) {
  // ...
} else {
    return NodeTraverser::DONT_TRAVERSE_CHILDREN;
}

return null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@staabm staabm marked this pull request as ready for review September 11, 2023 15:50
Copy link
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, Trigger Rectify needs to be run on rector-src code base after this PR merged to ensure nothing oversight :)

@samsonasik
Copy link
Member

Thank you @staabm

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

Successfully merging this pull request may close these issues.

UseImportsTraverser optimization opportunity
2 participants