-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
[performance] Use static variables inside every singleton constructors. #77
Conversation
e2129ef
to
0f129ec
Compare
I don't think it make sense to try and fix the code coverage for a static variable check, but if you think so, please let me know how and I can make the changes. |
Hi, I don't think Plus, in the next version (0.6), these classes will be converted to PHP 8.1 enums, so it won't be long before you get a much bigger improvement. I agree with all the others, though!
I still prefer to get it covered, so you can just add a test for each method that calls it twice and ensures that it returns the same instance! |
0f129ec
to
19fb90d
Compare
19fb90d
to
ca4b381
Compare
Tests added, reverted PS: i find it unexpected that ECS is configured with |
I tend to agree. @tigitz Do you want to change this? |
Yeah it's a matter of preference as explained here: https://docs.phpunit.de/en/10.3/assertions.html The idea I guess from this rule would be to at least force consistency throughout the codebase. But if you don't mind having both usage then I can remove it. Let me know. @BenMorel Taking the opportunity to friendly remind you about the dedicated PR about CI and codestyle that is still pending your review 😉 |
Thank you, @gnutix!
Definitely! I was thinking about switching to
I know, I'm sorry, I'm still a bit unsure about whether this is the way I want things, so I postponed indefinitely 😕 But the lack of coding standards on the other libraries really bothers me, so I'll have to take a decision at some point. In the meantime, if you want to change the PHPUnit code style, a PR is welcome 🙂 |
return $epoch; | ||
} | ||
|
||
return $epoch = new Instant(0, 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.
/** @var Instant|null $epoch */
static $epoch;
if (!isset($epoch)) {
$epoch = new Instant(0, 0);
}
return $epoch;
I think this variant is simpler, more cache-way
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.
Agree. That's how I spontaneously wrote the PR, then I changed it to match the current code style..
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.
I don't mind if you want to change this.
If you do, please use if ($epoch === null)
instead of isset()
, which wouldn't alert on undefined variable!
Hello folks,
Here's another performance optimization when static constructors are called a lot. It was already done for some methods in the library, so I kept the same code style and applied it to all static constructors that take no arguments ("constants", in a way).
Let me know if you think some of these do not deserve it. I applied it everywhere without much thinking about it, because I don't think there's any downside of having that static variable, and I definitely know that some of these methods show up a lot in our benchmarks, like
TimeZone(Offset)::utc()
andDuration::zero()
,min()/max()
, etc, and then it's definitely beneficial.