-
Notifications
You must be signed in to change notification settings - Fork 451
Immutable value objects for dispatch results #302
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
base: master
Are you sure you want to change the base?
Conversation
Marks the classes as `readonly` and makes use of constructor property promotion. The reason for this change is to allow consumers to safely create immutable results that can be used in tests. Previously, without the constructor, consumers using SA tooling could not set the readonly properties after construction.
|
I need to investigate this one... when I introduced the result object I saw negative impact on the benchmark using the constructor... Out of curiosity, why do you need to instantiate this? |
|
The main reason for this patch is so I can instantiate result values without writing to I ran the benchmarks locally with a retry threshold of 5 with:
Looks to me like that's not an insignificant performance penalty. I wonder if a static/named constructor might improve things 🤔 master vs current
|
|
Update: I tried dropping the constructor and moving instantiation to a static factory method like: /**
* @param array<string, string> $variables
* @param ExtraParameters $extraParameters
*/
public static function new(
mixed $handler,
array $variables = [],
array $extraParameters = [],
): self {
$instance = new self();
$instance->handler = $handler;
$instance->variables = $variables;
$instance->extraParameters = $extraParameters;
return $instance;
}This had little effect on the performance penalty, also removing Please feel free to close 👍 |
|
It's related to the additional calls happening at opcode level, which is also why Doctrine hydrates objects using serialisation 😅 I'll have a look at the patch in the adapter once I'm on a laptop 👍 |
Whilst working on the Mezzio adapter for FastRoute, I noticed it's "impossible" to create dispatch results without writing to soft
@readonlyproperties.Psalm hates that… so I took the liberty of dropping PHP 8.1, and making the results
readonlyclasses with constructors.Mainly this is useful in testing…
I've also added 8.5 to CI
Sorry if this patch is doing too much 😬