Uh oh!
There was an error while loading. Please reload this page.
refactor: AuthToken/AuthJWT Config Loading by Initializing in Constructor - #1252
refactor: AuthToken/AuthJWT Config Loading by Initializing in Constructor#1252datamweb wants to merge 3 commits into
AuthToken/AuthJWT Config Loading by Initializing in Constructor#1252Conversation
AuthToken Config Loading by Initializing in ConstructorAuthToken/AuthJWT Config Loading by Initializing in Constructor
paulbalandan
left a comment
There was a problem hiding this comment.
Do you have a benchmark for this change?
datamweb
commented
Feb 16, 2025
The presence of Optimize probably led to this question. It seems I made a mistake in choosing it, as my main goal in this configuration was to prevent the repeated use of But now I’m curious—does this change actually impact performance or not? Your benchmark results could be really helpful! @paulbalandan If possible, please share them so we can analyze them together. |
paulbalandan
commented
Feb 17, 2025
Yes, the word Optimize in your PR title made me curious about the impact to performance since we will now be loading the configs everytime a class is instantiated. I just remembered one time when I did a similar change to the Seeder class instantiating Faker's Generator everytime in the constructor caused a massive slowdown. |
michalsn
commented
Feb 27, 2025
Are we actually calling an |
AuthToken/AuthJWT Config Loading by Initializing in ConstructorAuthToken/AuthJWT Config Loading by Initializing in Constructordatamweb
commented
Feb 27, 2025
I didn't quite understand your question, and I'm not sure how it relates to this PR. Could you please clarify? |
michalsn
commented
Feb 28, 2025
Sorry, your reason for this change was described as:
So my question is. is this really the case? Are we actually calling these configs multiple times, or only once per request? |
datamweb
commented
Feb 28, 2025
In fact, the configuration is only called once per request. Therefore, it seems this change wouldn’t have a significant impact on performance. 100% Which one do you find more suitable and why?" First method: <?phpdeclare(strict_types=1);
class MyClass
{
publicfunction__construct() {
$this->config = config('Xconfig');
}
publicfunctionY()
{
$this->config;
}
publicfunctionX()
{
$this->config;
}
}Second method: <?phpdeclare(strict_types=1);
class MyClass
{
publicfunction__construct() {}
publicfunctionY()
{
$config = config('Xconfig); } public function X() { $config = config('Xconfig);
}
} |
michalsn
commented
Feb 28, 2025
Ok, sorry - that was my mistake. I thought we call this config only in one method. But now I see we call it several times. |
Description
AuthTokenandAuthJWTConfig Loading by Initializing in ConstructorChecklist: