doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.86k stars 2.5k forks source link

Remove doctrine/instantiator #11498

Closed derrabus closed 5 days ago

derrabus commented 1 week ago

I'd like to remove doctrine/instantiator from our dependencies.

I had a chat with @sebastianbergmann the other day and he told me how relieved he was that he could remove doctrine/instantiator from PHPUnit's dependencies because ReflectionClass::newInstanceWithoutConstructor() has become a drop-in replacement for all of his use-cases. This made me wonder if that weren't also the case for the ORM.

Is there any situation where instantiator would simply call ReflectionClass::newInstanceWithoutConstructor()?

beberlei commented 1 week ago

The instantiating part is not really needed anymore, but afair it only does that once and then clones the objects, because that was faster at the time.

looks like its still factor 10x faster:

<?php

$reflection = new ReflectionClass(stdClass::class);

$start = hrtime(true);
for ($i = 0; $i < 1000; $i++) {
    $foo = $reflection->newInstanceWithoutConstructor();
}
echo hrtime(true) - $start;
echo "\n";

$start = hrtime(true);
$foo = $reflection->newInstanceWithoutConstructor();
for ($i = 0; $i < 1000; $i++) {
    $bar = clone $foo;
}
echo hrtime(true) - $start;
echo "\n";
beberlei commented 1 week ago

But I would be 👍 for inlinng the code into the repo to reduce reliance on mini dependencies.

derrabus commented 5 days ago

The instantiating part is not really needed anymore, but afair it only does that once and then clones the objects, because that was faster at the time.

looks like its still factor 10x faster:

Thank you for clarifying. Let's keep the current logic then.