laravel injection core have any effect in performance?

laravel injection core have any effect in performance?



I inject my repository into my controller through a serviceProvider.



question 1: What is the performance impact of injection through the reflection of laravel injection core? Is it different from creating a new instance object inside the controller?
What is the impact if my serviceProvider binds many classes through Laravel's singleton pattern?



question 2: In singleton pattern, is an object creates in every request to the server?
After a finished request, is the singleton object destroyed or cached and reused?






For each request the whole stack is ran again (if you let app error out you can see whoops message + whole stack trace, so every single time you hit a server this stack is ran over and over again). Its all about readability & testability not what is more performant. If you want to have cutting edge performance use C instead.

– Kyslik
Sep 9 '18 at 14:41




1 Answer
1



The general advice when it comes to performance, is to only optimise for it when it becomes a problem - and even then, only do so with performance metrics in hand.



As for the performance impact of using the Laravel injection container, it's going to depend on how you use it.



When relying on it's auto-wiring functionality, you may indeed see some performance loss, because the container needs to use Reflection to determine the type of parameters needed to construct the object.
It may be faster to manually bind the service, in which case only a lookup in a hash map is required.



As for question 2, php operates a bit in the middle of the two. Most php servers will make a cache with the bytecode, so that interpreting will go faster after the first time. However PHP is built in such a way that all objects are removed from memory after the request is finished.



This can cause some performance loss, but it is also a nice way to ensure there is no memory leakage and fits well in the HTTP/REST concepts of statelessness.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)