yiisoft / di

PSR-11 compatible DI container and injector
https://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
183 stars 46 forks source link

Feature: caching #111

Closed viktorprogger closed 3 years ago

viktorprogger commented 4 years ago

We can introduce dependecy caching in order to make container faster. I'd like to see a decision that will result into some php files with methods like these:

public function getSomeDependency(ContainerInterface $container)
{
    return new SomeDependency($container->get('anotherDependency'));
}

public function getAnotherDependency(ContainerInterface $container)
{
    return new AnotherDependency();
}
samdark commented 4 years ago

That's good and bad at the same time. Good because yes, likely it would be more performant. Bad because you're executing not what you've actually written so debugging becomes quite weird experience.

armpogart commented 4 years ago

Maybe it's better to have a way to generate compiled container for production use-case and document it the way PHP-DI and Symfony do it.

samdark commented 4 years ago

@armpogart as I've mentioned, it's both good an bad. Need to check if performance gain worth the trouble.

viktorprogger commented 3 years ago

Some time passed... Now I think the best way to increase performance by dependency caching is either RoadRunner/Swoole/etc., or php preloading usage. Everything will be created just once :)

samdark commented 3 years ago

Yeah. That's the way to go. I think we can close this issue. Container reset is a separate one.