Performance: Early return in PhpDocNode refactoring for class renames#3509
Conversation
samsonasik
left a comment
There was a problem hiding this comment.
The origNode only be updated after node refactored, so it may be overlapped with "just updated" node.
"origNode" attribute usually used to verify node just reprinted.
I think it should be node, if it broke the test, something may happen in the middle.
|
Using node does not work here, because of your internal caching in Because there you cache the phpDocInfo by node, even if the node by have changed: $objectHash = spl_object_hash($node);
if (isset($this->phpDocInfosByObjectHash[$objectHash])) {
return $this->phpDocInfosByObjectHash[$objectHash];
}What happened in the case of the failed test was:
The current implementation in the class renamer relies on the following workflow:
As the code currently relies on the underlying caching mechanism i didn't want to change the behaviour of how that all works to much My current approach here is that when a node did not have a doc comment in the original source code, it also never needs to be refactored so we can do a early return here which is a lot faster, so i think checking the original node is a valid approach Does that make sense? |
|
I will let @TomasVotruba decide on this then |
|
The code is very hard to read and understand. We can improve the performance here, but I'd prefer more clear and self-explanatory code. |
|
I clearified the code by extracting the multiple if check to it's own method and gave it a better name and added some explanatory comments |
|
Thanks for the update, this looks good 👍 |
|
@keulinho @TomasVotruba it cause error in latest main tests unfortunatelly, it needs to be reverted https://github.com/rectorphp/rector-src/actions/runs/4902565356/jobs/8754485599#step:5:78 |
|
I see 👍 Thanks @samsonasik |
Another micro optimization bringing ~3% in our case: https://blackfire.io/profiles/compare/92f9a385-14c9-496c-8351-7be1d348e0bf/graph