Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pom's avatar
Level 21

About to Go Back to Inertia - Change My Mind

I've got a page that displays 50+ rows in a table and each row has three select (autocomplete) Flux UI components that are populated with a list of usernames (300+). I'm using a computed prop for the users so the DB bit is snappy. However, the server will run out of resources and crash. If I limit it to 45 rows the server stays up but takes 10+ seconds to load the page and uses 230+ MB of memory (Chrome's memory also spikes by 1GB). I tried making each row it's own Livewire component but the model count hit astronomical numbers (90,000+). I've tried offloading the heavy lifting to Javascript with the code below (surprised it worked). It takes about 5 seconds and uses 35 MB of memory so still not great.

<div x-data="{ options: {{ json_encode($this->users) }} }">
            <flux:select wire:model="user_id" variant="combobox" placeholder="Select...">
                <template x-for="option in options">
                    <flux:select.option x-text="option.name"></flux:select.option>
                </template>
            </flux:select>
        </div>

What am I doing wrong? Inertia handles the same page in less than a second using 3 MB of memory.

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like you're facing performance issues due to the large number of rows and the heavy data being loaded into the DOM. Here are a few strategies you can consider to improve the performance of your Livewire component:

  1. Lazy Loading or Pagination: Instead of loading all 50+ rows at once, consider implementing lazy loading or pagination. This way, you only load a subset of the data initially and load more as needed.

  2. Debounce Input: If you're using Livewire for real-time updates, consider debouncing the input to reduce the number of requests being sent to the server. This can be done using Livewire's wire:model.debounce modifier.

  3. Optimize Data Structure: Ensure that the data structure you're using is as efficient as possible. For example, if you're sending a large array of users, make sure you're only sending the necessary data (e.g., user IDs and names).

  4. Use Inertia for Heavy Lifting: Since you mentioned that Inertia handles the page more efficiently, consider using Inertia for this specific component. Inertia can handle large datasets more efficiently by leveraging client-side rendering.

  5. Virtual Scrolling: Implement virtual scrolling for the table. This technique only renders the rows that are currently visible in the viewport, which can significantly reduce the memory footprint.

  6. Optimize JavaScript: If you're offloading work to JavaScript, ensure that your JavaScript code is optimized. Avoid unnecessary re-renders and use efficient data structures.

Here's a basic example of how you might implement pagination with Livewire:

// In your Livewire component
public $perPage = 10;

public function loadMore()
{
    $this->perPage += 10;
}

public function getUsersProperty()
{
    return User::paginate($this->perPage);
}
<!-- In your Blade view -->
<div>
    @foreach($this->users as $user)
        <div>{{ $user->name }}</div>
    @endforeach

    @if($this->users->hasMorePages())
        <button wire:click="loadMore">Load More</button>
    @endif
</div>

By implementing these strategies, you should be able to improve the performance of your Livewire component. If Inertia is already working well for you, it might be worth considering using it for this specific use case.

jlrdw's avatar

I use server fetched partials and lookup tables instead of dropdowns. That way I have search, pagination, etc.

https://laracasts.com/discuss/channels/laravel/can-i-redirect-a-get-request-to-a-post-request-for-inertia-partial-reloads?page=1&replyId=905775

Just a quick example I put together, not real styling was done.

At a trucking company I used many such lookups for:

  • carrier
  • customer
  • picks locations
  • drops locations
  • etc

To me it was better than any drop down with a lot of rows. Especially with a pre-search to narrow down the results. And pagination as well when needed.

I never had any memory problems with this technique.

And I wrote my own tables, I have never needed "datatables" or anything like that. I have my own inline edit, add on the fly, etc. I use regular javascript with axios js to retrieve data.

Years ago I used jquery.

The trick is, go through the learning curve once, then you probably won't need other JS libraries.

Also always query only whats needed.

Edit:

If you have seen this I suggest watching it:

https://laracasts.com/series/inertia-2-unleashed

Please or to participate in this conversation.