The full video and many others like it are all available as part of our Frontend Masters subscription.

Rachel Nabors

Rachel Nabors is a CSS animations fanatic and award-winning cartoonist. A regular conference speaker, she ignites new technology with her experience in visual storytelling.

Rachel Nabors

Web Animation

Two more browser developer tools that are useful when auditing performance are Paint Flashing and the Timeline. Paint Flashing displays the regions of the page that are being repainted by the browser. Since repainting can cause performance issues, this helps you identify where the browser’s resources are being used. The timeline allows you capture and analyze a webpage’s loading, scripting, rendering and painting over a period of time.

Get Unlimited Access Now

Speaker 1: Okay, so now you've seen frames per second meter. It's all right, but it's not conclusive. How do we actually use the browser tools to sniff out some issues that we might be having? Well, there's one thing that I really like. Chrome's DevTools have this thing called Paint Flashing.

You know what, I'll just show it to you. So we talked a bit how there's layout, there's painting, and there's compositing, right? Paint flashing, what it does is it shows us where things are being painted, not composited, not laid out. Look, the whole page is green. The whole page is being painted.

That's not good. That's gotta cost money. So let's see what happens on my site when we do that. We're going to enable the paint flashing. Notice on my site, only the hands are being flashed because they're using background position. But notice what happens when I use the sidebar. The sidebar flashes green when it moves, and then flashes green again when it stops moving, showing that it's being painted only at the beginning and end of its animation.

That helps clarify how Chrome is handling those animations. So, it goes paint and then repaint. But notice, also, that more, this thing here, being sprite animation that I use background positioning on it, it stays green throughout its animation. What happens when we go to one of my other pages?

Oop, see, it turned green once the page stopped. The page is animated using a transform. Technically, we combine this using the slowdown animations to really get a view. That's wrong one, back, go back, abort, abort.
Speaker 1: So we could use this to go back home. And notice how, when we slow things down, we can really see when those paints come into play.

Speaker 1: And then there's the timeline tool. And the timeline tool's kind of heavy hitter here.
Speaker 1: If you notice that something is being really janky in certain places, it's a good idea to use this tool if you can. I'm going to go to Alice in Videoland and use it. And I'm going to turn off the paint flashing because if you are painting things, that can also change your performance.

I have seen two very different recordings. So what you're going to do is you're going to go to your Timeline tab. If it's not there, use the little arrows, go there. Or actually hang on, there's one thing I have to do. I'm afraid I've left it at 25%. I want to be at 100%.

We'll come back to that in a moment. So we're going to go down to
Speaker 1: Profiles
Speaker 2: Not in the dropdown.
Speaker 1: Timeline. Did it move that? Stop trying to be,
Speaker 2: When you click on it, it moves it up.
Speaker 1: Stop trying to be helpful, Chrome. You're not helping anybody.

So let's do it like this. And, I'm going to hit record. And it's got me this little buffer usage down here, which lets me know how long I have for recording.
Speaker 1: Or how long I'm recording. I'm going to scroll. I'm going to scroll this pretty fast because I want us get to one area where it can be problematic.

And I click the down button. We're going down. And there she's kicking. We're going to keep scrolling, scroll all the way to the down. And that should have fired something, but it's not. Might possibly be because we're recording it. Unfortunately, when we use tools like this which are really, really invasive, sometimes things don't behave the way we expect them to.

Or it could be because my code is wrong. Who knows? Now, you can't hear it, but my fans are going, my computer is very hot. And there we go. Now we got something we can work with. So, check it out. We even get, man, but it, we're going to have to I think break this out into its own window because it's that big.

My God, we've got to look at the whole thing as huge. This will check it out. We can actually see a little screenshot of what's happening at any given time. I went to the Chrome Dev Summit. And I asked for this feature. I'm glad I did. It's a lot easier to see where these bottlenecks are if you can visually see what's happening at that time.

Up here, you can see that we've got, at the very top of the bar, we can see that we've got these different mountain features in green. Those are measuring the FPS at any given time. And you can see, of course, where the FPS dropped. Here's a big dip.

Let's see what's happening here. Well, it looks like that was just when the teacup sat there for a little bit. And I don't know why it was like that. But perhaps it was because, if we go down here, we can have a look at all the mounds of listeners that I am calling at the same time.

Look, we can even, woh, this is Skrollr. Hi, Skrollr, good to see you. Yep.
Speaker 1: Does it not go past here? Does it not? Wow, you know what? Wow, this happened. So everybody, this should have shown the teacup dropping here. But Chrome actually trying to fell off the side of the wall on this one and stop taking screenshots, this happens sometimes.

Chrome Canary might be a little bit more reliable. I'd recommend you try this tool on that one. But Chrome Canary also tends to the change a lot. So I like to use it in regular old Chrome when I'm demoing it. But anyway after around here where you start seeing these changes, we can't see it.

But this is where events are happening, like where we're clicking on things. And you can find the actual triggers if you make your selection small enough, which I can't seem to get smaller. There we go, and we can actually see what's triggering some of these things.
Speaker 1: There we go.

So we've got jQuery Waypoints fires right here. We can see that there's a little dip. Did this cause the issue? Can't be 100% sure. Might have also been caused by the scroll event. Got a lot happening at the same time. But if you see these big dips, you could come in here and see what's firing right before them.

And that might be a tell that that event, whether it's a big repaint because repaints and such are listed in here too, whether or not that's the sort of thing that's causing it. And we can get rid of the screenshots and get rid of the JavaScript profile, or you can keep it.

You can get rid of the memory. I actually like the memory area. It's so big. And we have a lot of different things, like timer, function call, to doScroll. You can get really deep. And that is how we can actually find not just the JavaScript but also the CSS things that might be slowing us down.

Timeline tool is pretty complex. I do recommend you give it a look. But the best performance tip I can possibly, possibly give you is to not animate things that aren't visible. You might think that your browser is smart enough to not try to animate things when they're not onscreen.

But the truth is, if you have something spinning off the side of the screen, maybe it's a couple screens down or something, you've got a spin or they're going to around in circles, or maybe you have hundred of them there, the browser's actually paying attention to where those spinners should be when you finally get those spinners into view.

So, if they're not in view, they shouldn't be animated. You can use libraries like Waypoints.js to keep an eye on what's in view. And you can use this to help trigger animations since they're only playing when they're in view. And we can do that using states which we were playing with earlier.

States in view, I use the in view class quite a bit for triggering animations. Maybe one day, we'll have an even more above the board way to go about that.

Ready to take your code to the next level?

Intense courses with world-class teachers and unlimited access to our growing library of videos for the great price of $39 per month.

Get Unlimited Access Now