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?

haheute
  • 2,129
  • 3
  • 32
  • 49
  • On another note, if there's nothing regarding performance, is there any other reason to use Facades vs. helper functions? – John M. Oct 27 '15 at 17:29
  • 1
    I do not think there would be any performance boost. Those are static functions, so it won't make real difference. – Mina Abadir Nov 05 '15 at 20:36
  • 1
    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! – Halfpint Sep 27 '16 at 01:06
  • 2
    @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()`. – iRaS Aug 17 '17 at 11:50

1 Answers1

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.

lucidlogic
  • 1,814
  • 13
  • 15