Some people fear that running more than one container in their application will have a negative impact on performances. This article studies the impact on performance of using PHP-11's delegate lookup feature with a composite container.
One of PSR-11's key point is allowing 2 PHP dependency injection containers to work side-by-side (and to share entries). This is done through a mechanism called "delegate dependency lookup". The whole mechanism is detailed in the META document. While working on PSR-11, I encountered quite a lot of criticism regarding the idea of having 2 or more containers side-by-side. Most comments were in one of those 2 categories:
- You should not do this because [insert philosophical reason here]
- You should not do this because it will bad for performances
I really don't care about any philosophical comment you might have, but I do care a lot about performance. The comment about performance makes sense. If we must test if an entry is available in many containers instead of one, there has to be a performance impact. The question is: is it big enough to be noticeable? So I decided to run a test to see if I could detect any impact on performances from an application with multiple containers.