Your SlideShare is downloading. ×
0
Chrome DevToolsRendering & Memory profilingOpen Academy 2013 Mate Nadasdi - Ustream, Inc
WHY DO WE NEEDA DEVTOOL?
• Javascript is an interpreted language• HTML, CSS debugging have to happen in the browser• Logging, debugging network req...
Google is leading in new technologiesNative implementation and really fast supportCanary build deliver new features in rea...
Red - Yellow - Blue?Chrome channels• Stable (Releases in every 6 weeks)• Beta (1 month before stable, weekly releases)• De...
Rendering
Parsing (HTML, XML, CSS, Javascript)LayoutText and graphics renderingImage DecodingGPU interactionNetwork accessHardware a...
From source to display - The ordinary wayHTMLHTMLParserAttachmentCSS ParserStylesheetsLayoutShared bitmapDOM treeCSSOM tre...
Layout (Reflow) & RepaintLayout (reflow):Parts of the render tree needs to be revalidated and node dimensions should berecal...
Possible reflows & repaints• DOM actions (Add, Remove, Update DOM nodes)• Hide/show with display: none (reflow & repaint)• H...
Tips to minimize reflow & repaint• Try to minimize layout cost with smaller subtree modification• Detach DOM nodes before hu...
Compositing, You Are Welcome!• There are more GraphicContexts• New tree in our forest, Graphic Layer tree• Composited Rend...
Frames & Jank• 60 Hz = We have got 16.66 ms only! ( 60 Hz = 1 / ~0,016)• 60FPS is important, because 60Hz is average refre...
DEMO! Rock with timeline panel!Tips:• Show paint rectangles: Use it to show expensive paints• Show composited layer border...
Memory profiling
Javascript memory basicsRoot object• Top of the memory management system• We cannot manipulate• References global variable...
Object sizesShallow size• Memory held directly by the object• It can be significant for arrays and stringsRetained size• In...
Object’s retaining treeRootAGCDBHD object’s retaining tree is a graph, where paths are retaining paths from GC root to A.
GarbageGarbage:Variables wich are unreachable from the GC root nodeGarbage collection:Finds all garbages and frees it’s me...
Possible leaks• Closures• Deleting DOM nodes without removing event handlers• DOM could hold event listeners to objects wi...
DevTools workflow tips1. Search for possible memory leaks with timeline panel2. Use heap snapshots to capture object graph3...
DEMO!Tips:• Check counters during your interaction on the examined page• Use GC force button to see how it impacts on your...
Use Google Canary as it has all the features I have shownand more including lots of profiling experimentshttps://www.google...
Thank you!@matenadasdiSpecial thanks to Paul Irish and Addy Osmani for reviewing these slides.
Upcoming SlideShare
Loading in...5
×

Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013

6,217

Published on

Google Chrome DevTools presentation about Memory and Rendering profiling on Open Academy 2013 (05.23).

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,217
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
40
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Transcript of "Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013"

  1. 1. Chrome DevToolsRendering & Memory profilingOpen Academy 2013 Mate Nadasdi - Ustream, Inc
  2. 2. WHY DO WE NEEDA DEVTOOL?
  3. 3. • Javascript is an interpreted language• HTML, CSS debugging have to happen in the browser• Logging, debugging network requests is essential• Source and the final output could be totally different• Performance optimization is becoming increasingly important,especially on mobile
  4. 4. Google is leading in new technologiesNative implementation and really fast supportCanary build deliver new features in really short intervalsDeep configuration possibilitesEarly experimental accessRendering / Memory Profiling toolsWhy Google Chrome?
  5. 5. Red - Yellow - Blue?Chrome channels• Stable (Releases in every 6 weeks)• Beta (1 month before stable, weekly releases)• Dev (twice weekly)• Canary (daily)Chromium
  6. 6. Rendering
  7. 7. Parsing (HTML, XML, CSS, Javascript)LayoutText and graphics renderingImage DecodingGPU interactionNetwork accessHardware accelerationWebkit / Blink rendering engineImage Source: HTML5Rocks
  8. 8. From source to display - The ordinary wayHTMLHTMLParserAttachmentCSS ParserStylesheetsLayoutShared bitmapDOM treeCSSOM treeRender ObjecttreeRender Layertreen..1
  9. 9. Layout (Reflow) & RepaintLayout (reflow):Parts of the render tree needs to be revalidated and node dimensions should berecalculated.Repaint:Some part of the screen needs to be updated because of a reflow, node geometricchange or style change.
  10. 10. Possible reflows & repaints• DOM actions (Add, Remove, Update DOM nodes)• Hide/show with display: none (reflow & repaint)• Hide/show with visibility: hidden (repaint only because of no geometric change)• Adding stylesheet dynamically• scrolling, resizing the window• DOM queries can cause a reflow too• offsetTop/Left/Right/Height• scrollTop/Left/Right/Height• clientTop/Left/Right/Height• getComputedStyle
  11. 11. Tips to minimize reflow & repaint• Try to minimize layout cost with smaller subtree modification• Detach DOM nodes before huge manipulation• Do not change styles one by one (use classes instead)• Group DOM read and write actions to let the browser optimize reflows for you(DOM queries flush the browser’s queue of changes)• Cache queried values, do not query them in every case you use it
  12. 12. Compositing, You Are Welcome!• There are more GraphicContexts• New tree in our forest, Graphic Layer tree• Composited RenderLayers get their own backing surface• Upload painted bitmaps to the GPU as textures• 256x256 tiles• Different thread for compositing• Much cheaper then paint
  13. 13. Frames & Jank• 60 Hz = We have got 16.66 ms only! ( 60 Hz = 1 / ~0,016)• 60FPS is important, because 60Hz is average refresh rate of devices• Jank: every time you can’t create a frame when your screen refreshes• vSync - generating new frames only between screen refreshes• JavaScript timers fails because of inaccuracy and different frame rates• requestAnimationFrame is a good solution20ms 20ms 20ms 20ms 20ms 20ms 20msDisplay refresh at 60 hz:Our frame creation:
  14. 14. DEMO! Rock with timeline panel!Tips:• Show paint rectangles: Use it to show expensive paints• Show composited layer borders: Check your GPU compositing layers easily• Enable continuous page repainting: Easy to find the most expensive layers• chrome://tracing/: Detailed tracing system to track core functionalities• Use JavaScript CPU profile with Flame chart to diagnose your yellow pieces.
  15. 15. Memory profiling
  16. 16. Javascript memory basicsRoot object• Top of the memory management system• We cannot manipulate• References global variablesObject variable• Can reference other variablesScalar variable• number, boolean, etc
  17. 17. Object sizesShallow size• Memory held directly by the object• It can be significant for arrays and stringsRetained size• Indirect memory hold• A size what will be freed if the object will be terminated• For primitive types retained size equals shallow size
  18. 18. Object’s retaining treeRootAGCDBHD object’s retaining tree is a graph, where paths are retaining paths from GC root to A.
  19. 19. GarbageGarbage:Variables wich are unreachable from the GC root nodeGarbage collection:Finds all garbages and frees it’s memory to the systemLeak:Object that still has retaining path accidently
  20. 20. Possible leaks• Closures• Deleting DOM nodes without removing event handlers• DOM could hold event listeners to objects wich are inactive already• Cycles: two objects reference to each other when they retain each other
  21. 21. DevTools workflow tips1. Search for possible memory leaks with timeline panel2. Use heap snapshots to capture object graph3. Use all four views of the snapshot panel:• Summary: An overview of our heap grouped by constructor name• Comparison: Compare two snapshots• Containment: Structured view of object graph• Dominators: Find the most dominant points of the heap4. Use the new Object Allocation Tracker in DevTools experiments“Memory Lane with Gmail” talk about this new tool on Google IO 2013https://developers.google.com/events/io/sessions/325547004
  22. 22. DEMO!Tips:• Check counters during your interaction on the examined page• Use GC force button to see how it impacts on your memory• Use it in incognito window, because extension allocated memory will be listed too• Ignore:• line in parentheses• lines in light gray• GC collects garbage before snapshot execution
  23. 23. Use Google Canary as it has all the features I have shownand more including lots of profiling experimentshttps://www.google.com/intl/en/chrome/browser/canary.html
  24. 24. Thank you!@matenadasdiSpecial thanks to Paul Irish and Addy Osmani for reviewing these slides.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×