Laravel - performance of Facades vs. helper methods
Asked Answered
A

1

6

I wonder if there is a performance difference between using Facades and helper methods in laravel 5.1.

I startet to remove for example use View; or View::make() wherever possible, thinking that view() would be simpler and possibly faster. But I don't know.

Same with Redirect::to() --> redirect() , Redirect::back() --> back() and so on..

Is there a difference or does it not matter?

Allometry answered 9/7, 2015 at 17:19 Comment(4)
On another note, if there's nothing regarding performance, is there any other reason to use Facades vs. helper functions?Oballa
I do not think there would be any performance boost. Those are static functions, so it won't make real difference.Rosenberry
It's mainly stylistic, Facades basically provide a static interface to the underlying classes in the Laravels IoC container, meaning that you don't need to manually do dependency injection yourself. I prefer to use the helper functions as I don't like cluttering my code with static interface calls where I don't need too, however this will vary from developer to developer!Helicopter
@MinaAbadir why there should not be a performance boost? A facade is static call to Facade::__callStatic() -> static::getFacadeRoot() -> static::resolveFacadeInstance(static::getFacadeAccessor()) -> app()->make()->$method while the helper directly calls app()->make().Germanium
M
3

I don't think there is much performance difference but one thing to consider is the reduced cognitive load of always including the use statement when using a facade. Just one more thing to forget.

Machute answered 18/3, 2018 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.