Laravel Tip - Drastically Improve Memory Consumption and Query Time

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey what's up guys welcome to LaraTips, in  today's video i will be giving you a small   tip in laravel with which you can improve the  performance of your application drastically. So   without any further due let's get into it. As  you can see here in the dashboard controller,   i have these articles here. So i have fetched all  the articles and i have seeded 1000 articles in   the database. So if you see here in the database  i have this articles table and i have these fields   over here and if i show you the data over here so  you can see here there are a lot of data that i   have seeded here yeah so this is these titles logs  are normal strings and these sort description and   descriptions are the long text so we have so many  data here so in any article you can see a long   description there yeah so it's a real world  example and in the dashboard controller i have   just fetched the articles all the articles and i  have just returned it in the dashboard normally   in a news or any article website you will be  fetching a lot of articles and then you will   group them together and show them separately  in the home page that basically happens so we   are getting all the articles here for now okay so  now if i go here in the dashboard controller so i   am just commenting out this my previous tutorial  codes okay and this is the current one so i have   just looped through the articles and i have shown  articles title and the published_at date okay   so i have done only this but in a real case so  you would just group these articles by category   you will have the category or tags in the articles  and you will group them together here and you will   return to the view and you will show that in the  real world scenario basically you will fetch all   the articles in the initial phase and there also  comes some cashing and something like that but   currently we are not doing any caching here okay  so inside the dashboard just we are looping and   showing them and in the browser you can see here  in the dashboard so we are just showing this title   and this published_at date now if i refresh here  if you see it carefully if i refresh it over here   and at the bottom of this page so you can see here  it is using 19 mb of ram it is a lot of ram this   is using a lot of ram okay so here are a lot of  data so that's why it is using a lot of ram but by   doing some small tricks we can drastically reduce  the ram usage so you can here we are only showing   here this title and the published_at date and here  in the controller we are getting all the data from   the article so look here in the articles here so  we are getting all titles log image sort displays   description published at created at updated  every column data we are getting here so we   don't want all those data here yeah so we are only  showing here the title and the published at so we   will be only getting that so if you look  here in the query as well so in the browser   here this is the debug bar i'll leave the link  of this debug bar package in the description   below just below that like button so here in the  query you can see here select all from articles   so it is taking 25.8 milliseconds and it is also  consuming a lot of ram over here so now let us   only select those columns that we want so  if you see here closely so 19 mb of ram yeah   so now here in the code so if we say  select and we only want title and   published at now if we come here in the browser  and refresh the page now you can see here the   consumption of ram has been drastically reduced to  7 mb and the time for the execution of this query   has also been reduced to 2.99 milliseconds so  before it was i think it was around 20 to 25 yeah   so now that has also been drastically reduced  and the ram has also been drastically reduced   so guys in a very big project or very big data if  you don't want any data to be visible to the user   then don't fetch it from the database so if you  fetch it from the database then it will take a lot   of memory normally those columns that have very  huge amount of data in them it will take a lot of   ram and if your app is being used by a lot  of users then it will be very very slow so   after watching this video if your application is  running slowly then you can go ahead and remove   those columns that you don't want to be visible in  the user end or in the front end just do that and   check if your application becomes a little bit  faster so i hope you enjoyed this video guys if   you enjoyed this video then please don't forget to  hit that thumbs up button and also hit subscribe   button if you want to see more videos like this  thank you for watching have a great day bye
Info
Channel: Laratips
Views: 24,368
Rating: undefined out of 5
Keywords: laravel for beginner, laravel beginner tutorial, laravel tutorial for beginners, laravel 8 tutorial, laravel 8, laravel tutorial, laravel advanced, laravel 8 advanced, laravel advanced tutorial, laravel 8 advanced tutorial, php, php tips, php tips and tricks, tips and tricks, clean code, laravel performance, performance tip, reduce memory, improve memory usage, laravel query optimization, query optimization, laratips, laravel tips, laravel step by step
Id: i7bCDtrMYp0
Channel Id: undefined
Length: 4min 42sec (282 seconds)
Published: Mon Apr 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.