Playing
03. Using debugbar

Transcript

00:00
So the first thing that we're going to do is pull in an absolutely essential tool for building any Laravel project, and that is Laravel debug bar.
00:08
So we're going to pull this in and just take a look at the parts of this that we want to focus on the most. So let's head down to the installation instructions just here and we'll go ahead and pull this into our project.
00:22
And once that's done, we're pretty much ready to go. We don't need to configure anything. If we just head straight over to the browser here, give this a refresh, you can see that this pops up just at the bottom.
00:34
So the first tab that you can see is opened are the queries that are being run on the database. And as you can see here, there are quite a few queries being run. We're going to need to monitor this very,
00:46
very carefully so we don't run into any N plus one eager loading problems, which we're going to discuss in the next episode. We also want to keep an eye on the memory usage as well. This is pretty important and also the request duration.
01:01
So the request duration gives us an idea of, of course, the total time it has taken for everything here to load. You can also access that via your developer tools. So if you just head over to the network
01:13
tab, make sure you have all open and give the page a refresh. You can see the time just here as well, as well as any of your other assets that you have on the page. But most of the time we can just focus
01:24
on Laravel debug bar and that gives us a pretty accurate request duration. Now, these are the ones that we're going to be focusing on most in the course. But as we dive a little bit deeper, we can go into other things as well. For example, if you have nested views being
01:38
rendered and these were a little bit slow, you can check these out here. But most of the time we're going to focus on the query count and the memory usage, which is what slows down a page if we don't do things in the most performant way.
01:52
Now, just a tip on Laravel debug bar before we go any further, you can actually disable this if you need to at any point. If we just head over to our project and open up our EMV file and we come down and set debug bar enabled to false explicitly,
02:08
that's going to go ahead and disable that for us. Now, we're going to want to keep this to true and you're going to want to keep this to false in any testing environments or staging environment. This won't be installed on production
02:21
environment because when we pull this in, we use the if we just have a look up here, dev flag just here, so that will only be installed on a production environment if we're not including developer dependencies, which we shouldn't anyway. But we're going to go ahead and enable this for our use just here.
02:39
So you can see here the first thing is we've got a huge amount of queries. We're going to tackle that in the next episode by taking a look at eager loading, which is probably one of the most effective things you can do for Laravel performance.
15 episodes1 hr 9 mins

Overview

Let's keep our Laravel applications feeling snappy! In this course, we cover the absolute fundamentals you need to keep in mind when building anything with Laravel.

While Laravel handles a lot for you, it's easy to fall into the trap of not considering and monitoring performance as you go. Keep these tips in your toolbelt, and you'll be able to develop faster apps, from the beginning.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.