Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

NordicJS: Fast but not Furious: Debugging User Interaction Performance Issues

327 views

Published on

This is a talk on interaction performance, presented at NordicJS on 5.09.2018

Published in: Software
  • Be the first to comment

NordicJS: Fast but not Furious: Debugging User Interaction Performance Issues

  1. 1. Front-end Dev & Designer at Lunar Logic Anna Migas Google Developer Expert
  2. 2. Anna Migas @szynszyliszys Fast but not furious: Debugging user interaction performance issues
  3. 3. Starability.css Repaintless.css Auroral.css
  4. 4. Perceived performance
  5. 5. Perceived performance First Meaningful Paint Time to interactive
  6. 6. Optimise Critical Rendering Path
  7. 7. Optimise Critical Rendering Path Use progress bars instead of spinners
  8. 8. Optimise Critical Rendering Path Use progress bars instead of spinners Have a placeholder content
  9. 9. Optimise Critical Rendering Path Use progress bars instead of spinners Have a placeholder content Start upload before user even decides to click the upload button
  10. 10. Perceived Performance?
  11. 11. ! "
  12. 12. Perceived Performance
  13. 13. LOADPerceived Performance
  14. 14. ! " Perceived load performance
  15. 15. ! Perceived performance !
  16. 16. Perceived performance First Meaningful Paint Time to interactive Smooth at all times
  17. 17. Agenda 1. Why sometimes interactions feel slow 2. Browser rendering and frames 3. Types of triggered changes in the UI 4. How to test for interaction performance 5. Potentially dangerous user interface patterns
  18. 18. J A N K
  19. 19. zdjęcie krzeseł https://jakearchibald.github.io/jank-invaders/
  20. 20. zdjęcie krzeseł https://jakearchibald.github.io/jank-invaders/
  21. 21. 60 fps 
 1000/60 = ~16.6ms
  22. 22. 60 fps 
 1000/60 = ~16.6ms 120 fps 
 1000/120 = ~8.3ms iPad Pro, Razer smartphone
  23. 23. How can we help the browser to make it on time?
  24. 24. Offload the main thread BUS main thread (UI) background thread (heavy task)
  25. 25. Offload the main thread 1. Use Web Workers for heavy tasks 2. Optimise the main thread
  26. 26. Offload the main thread 1. Use Web Workers for heavy tasks 2. Optimise the main thread
  27. 27. If we interact with a page, a browser needs to start serving frames (ideally 60 or 120 per second)
  28. 28. What a frame consists of?
  29. 29. What a browser does during these steps?
  30. 30. Change happens, an event is fired 1
  31. 31. Styles are recalculated 2
  32. 32. Layout is calculated 3
  33. 33. Layout
  34. 34. Everything is rasterised and painted to the layers 4
  35. 35. Paint
  36. 36. Paint
  37. 37. Layers
  38. 38. What creates new layers? 1. 3D or perspective transforms 2. Animated 2D transforms or opacity 3. Being on top/a child of a compositing layer 4. Accelerated CSS filters 5. In special cases <video>, <canvas>, plugins 6. will-change CSS property
  39. 39. .btn { background-color: white; border: 1px solid blue; will-change: transform; } .btn:hover { transform: scale(1.1); }
  40. 40. Every layer consumes memory. Use them wisely.
  41. 41. Compositing 5
  42. 42. Compositing
  43. 43. Compositing
  44. 44. Types of triggered changes
  45. 45. Layout change (Reflow) (width, margin-top, left)
  46. 46. Paint change (Repaint) (background-color, box-shadow, background-image)
  47. 47. Compositing change (transform, opacity)
  48. 48. How to test if we have a problem?
  49. 49. Reflows can be quite obvious…
  50. 50. …but for Repaints we might need better tools
  51. 51. Performance tab (Chrome or Firefox)
  52. 52. Layers tab (Chrome)
  53. 53. Rendering tab (Chrome)
  54. 54. Rendering tab (Chrome)
  55. 55. Paint flashing (Firefox)
  56. 56. Performance monitor tab (Chrome)
  57. 57. What are the potentially dangerous UI patterns?
  58. 58. Animations 1
  59. 59. Animations 1. Don’t overuse animations 2. Animate only transform and opacity if possible 3. For 120fps avoid requestAnimationFrame() 4. Don’t animate elements below other nodes (like fixed headers) 5. Don’t animate too many elements
  60. 60. Parallax effect 2
  61. 61. http://davegamache.com/parallax/
  62. 62. Parallax effect 1. Causes Paint Storms 2. Almost always bad 3. Don’t use scroll events 4. Don’t use background-position 5. Use 3D transforms and perspective if you need to: https://developers.google.com/web/updates/ 2016/12/performant-parallaxing
  63. 63. Fixed elements 3
  64. 64. https://jsipsum.lunarlogic.io/
  65. 65. Fixed elements 1. Repaints with every frame when scrolling 2. Use will-change property (or transform: translate3D(0,0,0)) to avoid repainting .fixed-element { position: fixed; will-change: transform; }
  66. 66. Scrolling events 4
  67. 67. Scrolling events 1. Don’t attach wheel or touch listeners to the whole document, use smaller areas instead 2. Take advantage of passive event listeners (use with polyfill): window.addEventListener("scroll", func, {passive: true});
  68. 68. Hover effects 5
  69. 69. Hover effects 1. If they are bound to happen often—you might consider using will-change property 2. Can be deadly if there are too many and can be easily triggered 3. Avoid effects triggering Layout or Paint: https://csstriggers.com/
  70. 70. Appending elements 6
  71. 71. Appending elements 1. Make sure not many elements will be affected 2. Try to separate the area (will-change, contain: layout) 3. Try not to change the size of area (for example use overflow property)
  72. 72. Takeaways 1. Jank happens when the browser doesn’t finish rendering a frame on time 2. Try to offload and optimise the main thread 3. Avoid content Reflows and Repaints 4. Don’t overuse layers 5. Test your website with Performance, Layers and Rendering tabs 6. Use responsibly potentially dangerous UI patterns
  73. 73. Resources 1. http://jankfree.org 2. https://dev.opera.com/articles/css-will-change-property 3. https://www.udacity.com/course/browser-rendering-optimization--ud860 4. https://www.html5rocks.com/en/tutorials/speed/layers 5. https://www.html5rocks.com/en/tutorials/speed/high-performance- animations 6. https://blog.logrocket.com/eliminate-content-repaints-with-the-new-layers- panel-in-chrome-e2c306d4d752 7.https://dassur.ma/things/120fps 8. https://developers.google.com/web/tools/chrome-devtools/speed/get- started
  74. 74. Thanks! Anna Migas @szynszyliszys

×