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.

Episode summary

In this episode, we're diving into one of the must-have dev tools for Laravel: the Laravel Debugbar. We start off by installing it (super straightforward—just follow the composer instructions and you're ready to go), and once that's done, you'll notice a slick new bar popping up at the bottom of your browser when you reload your project.

We'll take a tour of the Debugbar and look at some of its most useful panels, like the queries tab (where you can instantly see all the database queries being executed) and keep an eye on important metrics like memory usage and request duration. This is super helpful to spot things like N+1 query problems, which we mention we'll get deeper into next time.

We also touch on how you can check request duration through your browser's developer tools, but for the bulk of this course, we'll mostly work with Debugbar since it gives you a really clear picture right away.

As a quick best practice, you'll learn how to disable the Debugbar when needed (like in your staging or testing environments), and we point out that it's only installed as a dev dependency for safety—so it doesn't run in production.

By the end of this episode, you'll be comfortable installing and exploring Debugbar and you'll see just how many queries are running in your app right now. Next up, we're going to actually fix the "lots of queries" issue by looking at eager loading!

Episode discussion

No comments, yet. Be the first!