DEV Community

Cover image for Dynamic Livewire Load Performance
Nasrul Hazim Bin Mohamad
Nasrul Hazim Bin Mohamad

Posted on • Updated on

Dynamic Livewire Load Performance

In my previous post on Load Dynamically Livewire Components from Different Namespace, I've hit an issue which causing my boot time to load the Laravel application is very slow.

On my machine, it run about 500-800ms, but for my team, sometimes they hit around 5-6 minutes to load for just a page.

Before Changes

So the journey begin to find out what's the issue, why it's taking so long to boot up. At first, I'm looking at my route files, which I have a lot of route files been loaded dynamically like the following:

collect(glob(base_path('/routes/web/*.php')))
    ->each(function ($path) {
        require $path;
    });
Enter fullscreen mode Exit fullscreen mode

Then I change the route to:

require 'web/_.php';
require 'web/user.php';
Enter fullscreen mode Exit fullscreen mode

Well, not much different, just about -10ms better.

So digging up my codes, see, what other things may caused until I remembered that I have a service provider, which load dynamic Livewire components in different domains in app/ directory.

One thing I noticed, I misconfigured to load the Livewire classes from /app instead of /app/Domains.

You can imagined how many files under app/ directory need to be load on initial load. 😬

With that in mind, I've tried to change from following:

public function register()
{
    if (class_exists(Livewire::class)) {
        $this->load(base_path(config('livewire-domain.path')));
    }
}
Enter fullscreen mode Exit fullscreen mode

To the following:

public function register()
{
    if (class_exists(Livewire::class)) {
        $this->load(config('livewire-domain.paths'));
    }
}
Enter fullscreen mode Exit fullscreen mode

And my config file as following:

'paths' => [
    app_path('Domain/Profile'),
    app_path('Domain/User'),
],
Enter fullscreen mode Exit fullscreen mode

Well the result?

After Changes

Top comments (0)