Santa Tracker Developer Diary #2: Performance & Layers

Chrome for Developers · Advanced ·📰 AI News & Updates ·8y ago

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 Polymer Performance Patterns (The Polymer Summit 2015)
Polymer Performance Patterns (The Polymer Summit 2015)
Chrome for Developers
2 Polymer Power Tools (The Polymer Summit 2015)
Polymer Power Tools (The Polymer Summit 2015)
Chrome for Developers
3 Chrome Dev Summit 2014 – Chrome Case Studies
Chrome Dev Summit 2014 – Chrome Case Studies
Chrome for Developers
4 Web Directions Code 2015 round up
Web Directions Code 2015 round up
Chrome for Developers
5 Maintainable Code - HTTP203
Maintainable Code - HTTP203
Chrome for Developers
6 iron-ajax… wat?! -- Polycasts #26
iron-ajax… wat?! -- Polycasts #26
Chrome for Developers
7 The Guardian - Supercharged
The Guardian - Supercharged
Chrome for Developers
8 ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
Chrome for Developers
9 #AskPolymer: Rob answers all the questions ever -- Polycasts #27
#AskPolymer: Rob answers all the questions ever -- Polycasts #27
Chrome for Developers
10 The Future of JavaScript - HTTP203
The Future of JavaScript - HTTP203
Chrome for Developers
11 Data Binding 101 -- Polycasts #28
Data Binding 101 -- Polycasts #28
Chrome for Developers
12 The Guardian part 2 - Supercharged
The Guardian part 2 - Supercharged
Chrome for Developers
13 The Future of Web Audio: with Chris Wilson and Chris Lowis
The Future of Web Audio: with Chris Wilson and Chris Lowis
Chrome for Developers
14 Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome for Developers
15 Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Chrome for Developers
16 #AskPolymer: How do you make the show? -- Polycasts #29
#AskPolymer: How do you make the show? -- Polycasts #29
Chrome for Developers
17 Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Chrome for Developers
18 Binding to Objects -- Polycasts #30
Binding to Objects -- Polycasts #30
Chrome for Developers
19 Player FM - Supercharged
Player FM - Supercharged
Chrome for Developers
20 Where’s the Designer? #AskPolymer -- Polycasts #31
Where’s the Designer? #AskPolymer -- Polycasts #31
Chrome for Developers
21 Jake Beats Wikipedia - HTTP203
Jake Beats Wikipedia - HTTP203
Chrome for Developers
22 Supercharged Observers! -- Polycasts #32
Supercharged Observers! -- Polycasts #32
Chrome for Developers
23 Jai's Web blog - Supercharged
Jai's Web blog - Supercharged
Chrome for Developers
24 Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Chrome for Developers
25 What about internationalization? #AskPolymer -- Polycasts #33
What about internationalization? #AskPolymer -- Polycasts #33
Chrome for Developers
26 Developing for Billions (Chrome Dev Summit 2015)
Developing for Billions (Chrome Dev Summit 2015)
Chrome for Developers
27 Google+ Performance Improvement Comparison
Google+ Performance Improvement Comparison
Chrome for Developers
28 Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Chrome for Developers
29 Progressive Web Apps (Chrome Dev Summit 2015)
Progressive Web Apps (Chrome Dev Summit 2015)
Chrome for Developers
30 Instant Loading with Service Workers (Chrome Dev Summit 2015)
Instant Loading with Service Workers (Chrome Dev Summit 2015)
Chrome for Developers
31 Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Chrome for Developers
32 Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Chrome for Developers
33 Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Chrome for Developers
34 Polymer - State of the Union (Chrome Dev Summit 2015)
Polymer - State of the Union (Chrome Dev Summit 2015)
Chrome for Developers
35 Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Chrome for Developers
36 Introduction to RAIL (Chrome Dev Summit 2015)
Introduction to RAIL (Chrome Dev Summit 2015)
Chrome for Developers
37 DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
Chrome for Developers
38 RAIL in the real world (Chrome Dev Summit 2015)
RAIL in the real world (Chrome Dev Summit 2015)
Chrome for Developers
39 #ChromeDevSummit talks are up - W00T! -- Polycast #34
#ChromeDevSummit talks are up - W00T! -- Polycast #34
Chrome for Developers
40 V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
Chrome for Developers
41 Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Chrome for Developers
42 Owning your performance: RAIL (Chrome Dev Summit 2015)
Owning your performance: RAIL (Chrome Dev Summit 2015)
Chrome for Developers
43 HTTP/2 101 (Chrome Dev Summit 2015)
HTTP/2 101 (Chrome Dev Summit 2015)
Chrome for Developers
44 Leadership Panel (Chrome Dev Summit 2015)
Leadership Panel (Chrome Dev Summit 2015)
Chrome for Developers
45 Build Processes, Totally Tooling Tips (S2, Ep 5)
Build Processes, Totally Tooling Tips (S2, Ep 5)
Chrome for Developers
46 Accessibility (Chrome Dev Summit 2015)
Accessibility (Chrome Dev Summit 2015)
Chrome for Developers
47 Binding to Arrays -- Polycasts #35
Binding to Arrays -- Polycasts #35
Chrome for Developers
48 HTTP2 - HTTP203
HTTP2 - HTTP203
Chrome for Developers
49 Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome for Developers
50 Call For Submissions - Supercharged
Call For Submissions - Supercharged
Chrome for Developers
51 Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Chrome for Developers
52 Testing AJAX with Web Component Tester -- Polycasts #37
Testing AJAX with Web Component Tester -- Polycasts #37
Chrome for Developers
53 Slack: Extended Xmas Special - Supercharged
Slack: Extended Xmas Special - Supercharged
Chrome for Developers
54 Browser testing with Travis & Sauce Labs -- Polycasts #38
Browser testing with Travis & Sauce Labs -- Polycasts #38
Chrome for Developers
55 Optimize for production with Vulcanize -- Polycasts #39
Optimize for production with Vulcanize -- Polycasts #39
Chrome for Developers
56 Highlights from Chrome Dev Summit 2015
Highlights from Chrome Dev Summit 2015
Chrome for Developers
57 Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome for Developers
58 Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Chrome for Developers
59 How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
Chrome for Developers
60 Colors – DevTools Tonight #0 (Pilot)
Colors – DevTools Tonight #0 (Pilot)
Chrome for Developers

Related Reads

📰
73% of tech job listings require AI skills now: 3 ways to show off yours
73% of tech job listings require AI skills, learn how to showcase yours to potential employers
ZDNet
📰
Hack suggests AI music generator Suno scraped YouTube for training data
AI music generator Suno allegedly scraped YouTube for training data, highlighting AI data sourcing concerns
TechCrunch AI
📰
South Korea will give all 52 million citizens free AI access, becoming the first G20 nation to do so
South Korea is offering free AI access to all 52 million citizens, making it the first G20 nation to do so, and you can learn from their innovative approach to AI adoption
The Next Web AI
📰
Learn AI Training from Industry Experts at Visualpath
Learn AI training from industry experts at Visualpath to future-proof your career
Dev.to · kalyan visualpath
Up next
OpenAI vs Anthropic
Matthew Berman
Watch →