Santa Tracker Developer Diary #2: Performance & Layers
Skills:
JavaScript Fundamentals80%
Key Takeaways
Deconstructs the countdown timer of the Santa Tracker site, focusing on performance and layers
Full Transcript
hey everyone it's Sam here on this episode of the Santa tracker series I'm going to talk a little bit about performance and performance in terms of the divs and the layers that we see on the page when we look at it so let's have a quick look at the site itself so what we see here is a bunch of divs and layers if you bring up the rendering tab in the bottom of your dev tools you'll see we have paint mop flashing and layer borders turned on so that's the effects you see the brown outlines are the layers that the GPU knows about and the green is where the GPU is currently drawing and so there's a lot of stuff going on you know Santa is a complicated site and we do render things as we go along this game for instance is causing a few redraws and you can kind of see some of our effects don't have drawing cost at all for instance this little cute scene of reindeers down here they don't actually need to be redrawn every frame we've done some work to make sure that they're only happening in the GPU which is pretty cool but of course for our countdown timer we quite literally draw a new number every second which makes sense so what we're trying to do is reduce the number of layers that were drawing so if you see in the example you'll see that the second counter is actually highlighting every frame and we don't really know why so let's have a look at that so this little counter here is our problem we also got this div at the top of this little green effect up here which is actually related and I'll explain why in just a second Sofer go to our source code and we can actually see that I've kind of commented things out rather than typing it in on the spot we want to change a couple of things so firstly this element only takes up about 70 pixels high and that's fine right that's how you want to use the element but note that it actually gets bigger around the top and bottom because we have this effect of this number appearing and disappearing as we as the number changes so what we're going to do and this is in SAS so you can see some some dollar sign variables here we're going to set the overflow so that overflow is going to be the size of the element in half so we want to make this element bigger by half on both sides so what we can do is set a negative margin to make the element bigger and sort of padding to make the elements smaller again what that means is we can force the GPU to make a bigger layer which is really good because it'll then contain our elements that move up and down as we count we've also said as the index and set the overflow:hidden because we can now tell the browser hey this layer which is now bigger really doesn't have anything outside it whereas previously our core layer actually couldn't be restricted right it would overflowed those things did expand out of its space so now if we hit save and hopefully refresh it should happen automatically we'll see that actually I've got this bigger element here but we've still got some problems here this is still flashing for some reason we don't quite understand what's actually happening here is this minutes and seconds an hour's thing that layer is on top of the numbers not below the numbers and that sounds a bit counterintuitive right because surely the numbers are kind of below the the text there but because they're in the wrong way the browser thinks that it needs to redraw that text every frame which isn't quite true so what we're gonna do is go down here and say this hold R which contains our number let's put it on top let's make it Z index much higher so this is a hundred here which is just a random value because we're in a stacking context it doesn't really matter what we choose so if we refresh the page and that happens automatically you'll see that now that number is just ticking up on its own so that's pretty much all I wanted to cover today hopefully what you've learned is a little bit about how to trick the browser into making bigger divs that are GPU layers and basically using things like Z index to basically convince the browser to only draw the bits you care about so thanks for watching and I'll see you next time thanks for watching you can subscribe to the google chrome developer channel down here we'll check out some other great videos over here
Original Description
Deconstruct the countdown timer, a core part of Santa Tracker, with Sam in this episode of the Santa Tracker 🎅🎄🎁 Developer Diary.
https://github.com/google/santa-tracker-web
https://santatracker.google.com
Watch the rest of the series here: https://goo.gl/UD214n
Subscribe to the Chrome Developers channel: http://goo.gl/LLLNvf
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Chrome for Developers · Chrome for Developers · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Polymer Performance Patterns (The Polymer Summit 2015)
Chrome for Developers
Polymer Power Tools (The Polymer Summit 2015)
Chrome for Developers
Chrome Dev Summit 2014 – Chrome Case Studies
Chrome for Developers
Web Directions Code 2015 round up
Chrome for Developers
Maintainable Code - HTTP203
Chrome for Developers
iron-ajax… wat?! -- Polycasts #26
Chrome for Developers
The Guardian - Supercharged
Chrome for Developers
ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
Chrome for Developers
#AskPolymer: Rob answers all the questions ever -- Polycasts #27
Chrome for Developers
The Future of JavaScript - HTTP203
Chrome for Developers
Data Binding 101 -- Polycasts #28
Chrome for Developers
The Guardian part 2 - Supercharged
Chrome for Developers
The Future of Web Audio: with Chris Wilson and Chris Lowis
Chrome for Developers
Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome for Developers
Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Chrome for Developers
#AskPolymer: How do you make the show? -- Polycasts #29
Chrome for Developers
Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Chrome for Developers
Binding to Objects -- Polycasts #30
Chrome for Developers
Player FM - Supercharged
Chrome for Developers
Where’s the Designer? #AskPolymer -- Polycasts #31
Chrome for Developers
Jake Beats Wikipedia - HTTP203
Chrome for Developers
Supercharged Observers! -- Polycasts #32
Chrome for Developers
Jai's Web blog - Supercharged
Chrome for Developers
Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Chrome for Developers
What about internationalization? #AskPolymer -- Polycasts #33
Chrome for Developers
Developing for Billions (Chrome Dev Summit 2015)
Chrome for Developers
Google+ Performance Improvement Comparison
Chrome for Developers
Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Chrome for Developers
Progressive Web Apps (Chrome Dev Summit 2015)
Chrome for Developers
Instant Loading with Service Workers (Chrome Dev Summit 2015)
Chrome for Developers
Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Chrome for Developers
Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Chrome for Developers
Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Chrome for Developers
Polymer - State of the Union (Chrome Dev Summit 2015)
Chrome for Developers
Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Chrome for Developers
Introduction to RAIL (Chrome Dev Summit 2015)
Chrome for Developers
DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
Chrome for Developers
RAIL in the real world (Chrome Dev Summit 2015)
Chrome for Developers
#ChromeDevSummit talks are up - W00T! -- Polycast #34
Chrome for Developers
V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
Chrome for Developers
Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Chrome for Developers
Owning your performance: RAIL (Chrome Dev Summit 2015)
Chrome for Developers
HTTP/2 101 (Chrome Dev Summit 2015)
Chrome for Developers
Leadership Panel (Chrome Dev Summit 2015)
Chrome for Developers
Build Processes, Totally Tooling Tips (S2, Ep 5)
Chrome for Developers
Accessibility (Chrome Dev Summit 2015)
Chrome for Developers
Binding to Arrays -- Polycasts #35
Chrome for Developers
HTTP2 - HTTP203
Chrome for Developers
Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome for Developers
Call For Submissions - Supercharged
Chrome for Developers
Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Chrome for Developers
Testing AJAX with Web Component Tester -- Polycasts #37
Chrome for Developers
Slack: Extended Xmas Special - Supercharged
Chrome for Developers
Browser testing with Travis & Sauce Labs -- Polycasts #38
Chrome for Developers
Optimize for production with Vulcanize -- Polycasts #39
Chrome for Developers
Highlights from Chrome Dev Summit 2015
Chrome for Developers
Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome for Developers
Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Chrome for Developers
How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
Chrome for Developers
Colors – DevTools Tonight #0 (Pilot)
Chrome for Developers
More on: JavaScript Fundamentals
View skill →Related Reads
📰
📰
📰
📰
73% of tech job listings require AI skills now: 3 ways to show off yours
ZDNet
Hack suggests AI music generator Suno scraped YouTube for training data
TechCrunch AI
South Korea will give all 52 million citizens free AI access, becoming the first G20 nation to do so
The Next Web AI
Learn AI Training from Industry Experts at Visualpath
Dev.to · kalyan visualpath
🎓
Tutor Explanation
DeepCamp AI