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
inline $other->getPrototype() to speedup equals() #4040
Conversation
@@ -156,34 +156,44 @@ public function clearChanged() | |||
*/ | |||
public function equals($other, $caseSensitive = true) | |||
{ | |||
$otherPrototype = $other instanceof self ? $other->getPrototype() : $other; | |||
if ($other instanceof self) { |
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.
not sure I got all cases right. we need to double-check and maybe increase test-coverage in case this is not yet covered.
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.
well, we see a failing test...
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.
tests fixed
src/Tokenizer/Token.php
Outdated
} | ||
|
||
if (array_key_exists(0, $otherPrototype) && $this->id !== $otherPrototype[0]) { | ||
if (\array_key_exists(0, $other) && $this->id !== $other[0]) { |
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.
please revert backslashing.
we rely on native_function_invocation
rule, that's it
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 path is very very hot, and paying this additional namespace lookup here makes a difference.
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.
How much difference?
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.
after #4041 its no longer measurable.
resubmitted with new merge base |
as measured in #4026 we try to speedup equals() by inlinening the $this->getPrototype() call.
also we use FQCN for native functions, because equals() is called a lot.
this speedsup the process by 4-5%.
see https://blackfire.io/profiles/compare/f4eefae8-6d09-4ab4-a833-f828d74a7b52/graph