How to make FilamentPHP faster

Hello, I am using FilamentPHP on a few of my projects and I kind of feel that V2 is much faster than V3. I am facing issues with slow sorting on table which uses a few sum and avg queries for each record on the table and also when I click on any action button on the table it takes a few seconds to load the modal for add or edit forms which also uses some relationship drop downs. I am using shared hosting for all my projects and I made a few admin panels with Alpinejs and Livewire which works a lot faster than Filamentphp admin panel. Please let me know what are the best practices to do to make it more user friendly and increase the performance. Thank you
18 Replies
mohdaftab
mohdaftabOP14mo ago
I have also used Debugbar and disabled view column and there are like 4 extra queries running for each record that shows on the table for the stats, sum and avg. Thank you Google Chrome Same even with Firefox
Dennis Koch
Dennis Koch14mo ago
How long does the database take and how long does Filament take?
mohdaftab
mohdaftabOP14mo ago
I am sorry for the late reply There are no errors in the console, browser cache is also clean as it happens with me as well as client's browser. I will try deleting the vendor folder in resources now. I have done the npm run build as well a few times I have checked the queries separately and it takes like 50 to 100ms for database query and with cache even less but I see the server response time is taking around 500ms and content download also taking around 700 to 800ms TextColumn::make("") ->label("Email Stats") ->getStateUsing(function ($record) { $text = []; if (null !== $record) { $text[] = "Sent: " . $record->email_trackings()->where("event_type", "delivery")->count(); $text[] = "Opened: " . $record->email_trackings()->where("event_type", "open")->count(); $text[] = "Clicked: " . $record->email_trackings()->where("event_type", "click")->count(); $text[] = "Bounced: " . $record->email_trackings()->where("event_type", "bounce")->count(); if ($record->email_trackings()->count()) { $last_email_sent = Carbon::createFromTimestamp(strtotime($record->email_trackings()->where("event_type", "delivery")->latest()->first()?->timestamp))->setTimezone("Europe/London")->format("Y-m-d H:i:s"); $text[] = "Last email sent: " . $last_email_sent; } else { $text[] = "Last email sent: Never"; } } return new HtmlString(implode("<br>", $text)); }) I am using this in the Table which runs these queries for each record. but in a few other tables I have which are slow and they don't have any queries like these
toeknee
toeknee14mo ago
Yeah that's going to be slow as you are running multiple large queries Why not have them as individual columns?
mohdaftab
mohdaftabOP14mo ago
The email trackings are using hasmanythrough relationship and they are being used separately as well. This table just shows the data belonging to that user but the email trackings have to be separate for other purpose. the add/edit forms also have around 4 drop downs with preloaded relationship data, can those be lazy loaded like after the modal is loaded ?
toeknee
toeknee14mo ago
Yes that's all it does, but for what you are doing is running 5 queries for every record on that data. after the intitial query
mohdaftab
mohdaftabOP14mo ago
I think it should be best to load them using withCount but I am not sure where to add those in Filamentphp
toeknee
toeknee14mo ago
->counts() and use the name as event_type_count bvut you should load them all as where'ed relationships
mohdaftab
mohdaftabOP14mo ago
yes because each event type has separate records
toeknee
toeknee14mo ago
Correct, but you load them all in at the same level just as part of the query opposed to individual queries
mohdaftab
mohdaftabOP14mo ago
I will take a look on this url and see how it goes. Thank you so much everyone. I will post the update here.
toeknee
toeknee14mo ago
No problem Also, make sure you have an index on the email_trackings for event_type.
mohdaftab
mohdaftabOP14mo ago
Ok thank you, it is already added 🙂
toeknee
toeknee14mo ago
IS this on live or local that it's slow too? Make sure to disable debug toolbar when testing performance.
mohdaftab
mohdaftabOP14mo ago
local is working better than live server because it has 8GB ram and server has only 1GB. I have set the memory_limit to 512MB on local and it still works better than server's. The issue is the delay when clicking on the edit button and the sorting all other features are working flawlessly, btw, just for asking I have mail folder in the resources/views/vendor and also npm run build command gives me errors λ npm run build npm ERR! Missing script: "build" npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run
Dennis Koch
Dennis Koch14mo ago
If you don't have Vite or anything configured you don't need to run that mail folder is not importants. It's about Filament views
mohdaftab
mohdaftabOP14mo ago
yes I don't have filament views on the vendor folder.
Want results from more Discord servers?
Add your server