SlideShare a Scribd company logo
Browsers
Magic is inside
Alex Tokarenko
tokarenko@devexperts.com
What we will talk about
• Browser internal components
• Main processes during page load or dynamic changes
• Performance tips and tricks
• Chrome Devtools in action
Why we will talk about it?
• Mostly used software in the world
• Internet Explorer 90% dominance
• Nowadays browsers not a "black box“
- they became opensource
High Level structure
Referenced rendering engines
All examples will be from source code of
WebKit, Blink, Gecko
Why? – Because they are open sourced
Rendering engine basic flow
Parse HTML to construct DOM tree
Render tree construction
Layout the render tree
Paint
Main components and processes
Parse HTML to construct DOM tree
Render tree construction
Layout the render tree
Paint
HTML Parser doings
• Parses input HTML tag soup
• Fixes web author mistakes
• Requests to load resources
• Constructs DOM tree
Turning ‘soup’ into DOM tree
HTML Language
• HTML approach is very "forgiving“
• HTML is not a context free grammar
• Can’t be parsed by XML parser
• Can’t be parsed by regular parsers (BNF)
• Defined in DTD (Document Type Definition)
Error tolerance example #1
WebKit source code:
if (m_inStrayTableContent && localName == tableTag)
popBlock(tableTag);
Error tolerance example #2
• Start with closed tag
• Not closed tags at all
Handling </BR> in WebKit code:
if (t->isCloseTag(brTag) && m_document->inCompatMode()) {
reportError(MalformedBRError);
t->beginTag = true;
}
HTML parsing flow
Special parsing algorithm because
• Forgiving nature of the language
• Historically lack of documentation developers
• Huge amount of invalid code
HTML parsers 'guesses' the intention of the code
author
Resources loading during parsing
• Scripts
• CSS
• Other resources
Scripts loading VS Page Latency
Script is loaded and executed
immediately when achieved
Parsing halts until script execution
Recommendation
• Put the script at the end of document
• HTML5 defer and async attributes
CSS Loading VS Latency
Can block scripts execution until loaded
Browsers are smart
Speculative parsers find resources references
to load in parallel threads
Parse HTML to construct DOM tree
Render tree construction
Layout the render tree
Paint
Rendering tree
Holds:
• Tree of visual elements in display order
• Style information, computed metrics
• Shadow DOM tree
Rendering tree VS DOM
Out of basic flow
• “display:none” elements are excluded
• Absolute and fixed position elements
• Non visual elements like <head></head>
Computed style
Performance impact
• Style is a very large construct
• Lookup for matching CSS rule can cause performance issues
div div div div {
…
}
• Applying rules is complex
Browsers are smart
• Style objects can be shared between render
objects
• Browser collect changes and process them
on demand
Parse HTML to construct DOM tree
Render tree construction
Layout the render tree
Paint
What is Layout process?
• Calculation of geometry and position
• Flow based model (left-to-right, top-to-bottom)
• Coordinate system relative to top left
coordinates
How Layout Process Works
• Parent determines its width
• Parent places children with right coordinates
• Accumulate children their heights
• Caches calculated values
Global Layout
• Occurs at least ones for whole tree
• Happens on global changes (like window resize)
Incremental Layout
Happens:
• When new element added to the tree
• When geometric attributes changes
Browser is smart
Usually changes are batched and done
asynchronously
However script accessing geometry attributes can force
synchronous layout
Synchronous layout
Synchronous layout demo
// Animation loop
function update(timestamp) {
for(var m = 0; m < movers.length; m++) {
movers[m].style.left = ((Math.sin(movers[m].offsetTop + timestamp/1000)+1) * 500) + 'px';
}
raf = window.requestAnimationFrame(update);
};
Painting
• Traversing the tree from the root
• Global and Incremental paint
• Dirty bit system
Painting order
CSS2 specification defines the order of the painting elements:
– background color
– background image
– border
– children
– outline
What can trigger REcalculations?
• Changes style will cause restyle and repaint of the element;
• Changes of position will cause relayout and repaint;
• Adding a DOM node will cause relayout and repaint of the
node.
• Major changes will cause invalidation of caches, relayout
and repaint
Recommendations
o Cache style values if possible for read
o Change Non-visible element and set it to visible
o Use documentFragment or cloned element and then swap it with
old one
o Use classes instead of inline styles
o Try to keep changes lower in the tree
How we make a deal with all this stuff?!
• Browser dev tools
– Timeline
– Logs
– Heap profiler
– Object allocations
– CPU Profiler
Links
• http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/
• http://taligarsiel.com/Projects/howbrowserswork1.htm
• https://developers.google.com/chrome-developer-tools/docs/demos/too-much-layout/
• http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/
• https://www.webkit.org/blog/114/webcore-rendering-i-the-basics/
• http://www.chromium.org/blink
• http://msdn.microsoft.com/en-us/library/aa741312(v=vs.85).aspx
• https://lists.webkit.org/pipermail/webkit-dev/2013-April/024436.html
• http://stackoverflow.com/questions/15804169/the-safari-javascript-engine-in-webkit
• http://www.html5rocks.com/en/tutorials/speed/script-loading/
• http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html
• http://royal.pingdom.com/2013/03/21/browser-wars-2013/
• http://www.html5rocks.com/en/tutorials/memory/effectivemanagement
• http://www.html5rocks.com/en/tutorials/speed/static-mem-pools
• http://www.html5rocks.com/en/tutorials/performance/mystery/
• http://en.wikipedia.org/wiki/V8_(JavaScript_engine)
• http://coding.smashingmagazine.com/2012/11/05/writing-fast-memory-efficient-javascript/
• https://code.google.com/p/v8/
Q?
Join us
Если Вам захотелось присоединиться к команде Devexperts,
пишите и звоните нам:
Тел.: (812) 438-16-26
E-mail: job@devexperts.com
Вакансии: hh.ru и itmozg.ru.
Наши новости: devexperts.com и ВКонтакте.
Контакты
Мы создаем качественное и эффективное ПО для
комплексной автоматизации брокерской, биржевой и финансовой
деятельности
Devexperts
Наша команда – это 300 профессионалов в области программирования,
тестирования и поддержки ПО

More Related Content

What's hot

Introduction to Browser Internals
Introduction to Browser InternalsIntroduction to Browser Internals
Introduction to Browser Internals
Siva Arunachalam
 
Firefox Architecture Overview
Firefox Architecture OverviewFirefox Architecture Overview
Firefox Architecture Overview
Anant Narayanan
 
How Browser Works?
How Browser Works?How Browser Works?
How Browser Works?
Vova Voyevidka
 
Android chromium web view
Android chromium web viewAndroid chromium web view
Android chromium web view
朋 王
 
DHTML - Dynamic HTML
DHTML - Dynamic HTMLDHTML - Dynamic HTML
DHTML - Dynamic HTML
Reem Alattas
 
Hardware Acceleration in WebKit
Hardware Acceleration in WebKitHardware Acceleration in WebKit
Hardware Acceleration in WebKit
Joone Hur
 
Chrome & Webkit overview
Chrome & Webkit overviewChrome & Webkit overview
Chrome & Webkit overview
Bin Chen
 
Languages and tools for web programming
Languages and tools for web  programmingLanguages and tools for web  programming
Languages and tools for web programming
Alamelu
 
Chrome Internals: Paint and Composition
Chrome Internals: Paint and CompositionChrome Internals: Paint and Composition
Chrome Internals: Paint and CompositionDzmitry Varabei
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be used
arya krazydude
 
Dhtml
DhtmlDhtml
Dhtml
Prassonu
 
OVERVIEW: Chromium Source Tree
OVERVIEW: Chromium Source TreeOVERVIEW: Chromium Source Tree
OVERVIEW: Chromium Source Tree
Chang W. Doh
 
Asp net
Asp netAsp net
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Android Chromium Rendering Pipeline
Android Chromium Rendering PipelineAndroid Chromium Rendering Pipeline
Android Chromium Rendering PipelineHyungwook Lee
 
Web component
Web componentWeb component
Web component
EngrHasanuzzamanSumo
 
Introducing asp
Introducing aspIntroducing asp
Introducing aspaspnet123
 
Oracle Forms Creation
Oracle Forms CreationOracle Forms Creation
Oracle Forms Creation
Sekhar Byna
 
Webform and Drupal 8
Webform and Drupal 8Webform and Drupal 8
Webform and Drupal 8
Philip Norton
 

What's hot (20)

Introduction to Browser Internals
Introduction to Browser InternalsIntroduction to Browser Internals
Introduction to Browser Internals
 
Firefox Architecture Overview
Firefox Architecture OverviewFirefox Architecture Overview
Firefox Architecture Overview
 
How Browser Works?
How Browser Works?How Browser Works?
How Browser Works?
 
Android chromium web view
Android chromium web viewAndroid chromium web view
Android chromium web view
 
DHTML - Dynamic HTML
DHTML - Dynamic HTMLDHTML - Dynamic HTML
DHTML - Dynamic HTML
 
Hardware Acceleration in WebKit
Hardware Acceleration in WebKitHardware Acceleration in WebKit
Hardware Acceleration in WebKit
 
Chrome & Webkit overview
Chrome & Webkit overviewChrome & Webkit overview
Chrome & Webkit overview
 
Languages and tools for web programming
Languages and tools for web  programmingLanguages and tools for web  programming
Languages and tools for web programming
 
Chrome Internals: Paint and Composition
Chrome Internals: Paint and CompositionChrome Internals: Paint and Composition
Chrome Internals: Paint and Composition
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be used
 
Dhtml
DhtmlDhtml
Dhtml
 
OVERVIEW: Chromium Source Tree
OVERVIEW: Chromium Source TreeOVERVIEW: Chromium Source Tree
OVERVIEW: Chromium Source Tree
 
Asp net
Asp netAsp net
Asp net
 
Web browser
Web browserWeb browser
Web browser
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Android Chromium Rendering Pipeline
Android Chromium Rendering PipelineAndroid Chromium Rendering Pipeline
Android Chromium Rendering Pipeline
 
Web component
Web componentWeb component
Web component
 
Introducing asp
Introducing aspIntroducing asp
Introducing asp
 
Oracle Forms Creation
Oracle Forms CreationOracle Forms Creation
Oracle Forms Creation
 
Webform and Drupal 8
Webform and Drupal 8Webform and Drupal 8
Webform and Drupal 8
 

Viewers also liked

How to improve java performance
How to improve java performanceHow to improve java performance
How to improve java performance
Devexperts
 
Effective websites development
Effective websites developmentEffective websites development
Effective websites development
Devexperts
 
Drd secr final1_3
Drd secr final1_3Drd secr final1_3
Drd secr final1_3Devexperts
 
20130420 bitbyte
20130420 bitbyte20130420 bitbyte
20130420 bitbyteDevexperts
 
Windows, doors and secret passages: approaches to the space organization in t...
Windows, doors and secret passages: approaches to the space organization in t...Windows, doors and secret passages: approaches to the space organization in t...
Windows, doors and secret passages: approaches to the space organization in t...Devexperts
 
Codefreeze rus
Codefreeze rusCodefreeze rus
Codefreeze rus
Devexperts
 
Codefreeze eng
Codefreeze engCodefreeze eng
Codefreeze eng
Devexperts
 
Dynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDevexperts
 
ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review
Roman Elizarov
 

Viewers also liked (9)

How to improve java performance
How to improve java performanceHow to improve java performance
How to improve java performance
 
Effective websites development
Effective websites developmentEffective websites development
Effective websites development
 
Drd secr final1_3
Drd secr final1_3Drd secr final1_3
Drd secr final1_3
 
20130420 bitbyte
20130420 bitbyte20130420 bitbyte
20130420 bitbyte
 
Windows, doors and secret passages: approaches to the space organization in t...
Windows, doors and secret passages: approaches to the space organization in t...Windows, doors and secret passages: approaches to the space organization in t...
Windows, doors and secret passages: approaches to the space organization in t...
 
Codefreeze rus
Codefreeze rusCodefreeze rus
Codefreeze rus
 
Codefreeze eng
Codefreeze engCodefreeze eng
Codefreeze eng
 
Dynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programs
 
ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems ReviewACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review
ACM ICPC 2014 NEERC (Northeastern European Regional Contest) Problems Review
 

Similar to Browsers. Magic is inside.

Vlad zelinschi optimizing the critical rendering path
Vlad zelinschi   optimizing the critical rendering pathVlad zelinschi   optimizing the critical rendering path
Vlad zelinschi optimizing the critical rendering path
Codecamp Romania
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
Gil Fink
 
Web Components at Scale, HTML5DevConf 2014-10-21
Web Components at Scale, HTML5DevConf 2014-10-21Web Components at Scale, HTML5DevConf 2014-10-21
Web Components at Scale, HTML5DevConf 2014-10-21
Chris Danford
 
web development
web developmentweb development
web development
RamanDeep876641
 
Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflowPeter Kaizer
 
025444215.pptx
025444215.pptx025444215.pptx
025444215.pptx
RiyaJenner1
 
WEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptxWEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptx
silvers5
 
Html,CSS & UI/UX design
Html,CSS & UI/UX designHtml,CSS & UI/UX design
Html,CSS & UI/UX design
Karthikeyan Dhanasekaran CUA
 
25444215.pptx
25444215.pptx25444215.pptx
25444215.pptx
YashMittal302244
 
web development
web developmentweb development
web development
ABHISHEKJHA176786
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
FITC
 
Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG) Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG) Mediacurrent
 
Incremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentIncremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend Development
Akihiro Ikezoe
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!
Aleks Zinevych
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web components
Mike North
 
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...BIWUG
 
Introduction to HTML language Web design.pptx
Introduction to HTML language Web design.pptxIntroduction to HTML language Web design.pptx
Introduction to HTML language Web design.pptx
lekhacce
 
Spsbe using js-linkanddisplaytemplates
Spsbe   using js-linkanddisplaytemplatesSpsbe   using js-linkanddisplaytemplates
Spsbe using js-linkanddisplaytemplates
Paul Hunt
 
ppt.ppt
ppt.pptppt.ppt
ppt.ppt
Sana903754
 

Similar to Browsers. Magic is inside. (20)

Vlad zelinschi optimizing the critical rendering path
Vlad zelinschi   optimizing the critical rendering pathVlad zelinschi   optimizing the critical rendering path
Vlad zelinschi optimizing the critical rendering path
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Web Components at Scale, HTML5DevConf 2014-10-21
Web Components at Scale, HTML5DevConf 2014-10-21Web Components at Scale, HTML5DevConf 2014-10-21
Web Components at Scale, HTML5DevConf 2014-10-21
 
web development
web developmentweb development
web development
 
Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
 
025444215.pptx
025444215.pptx025444215.pptx
025444215.pptx
 
WEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptxWEB DEVELOPMENT.pptx
WEB DEVELOPMENT.pptx
 
Performance (browser)
Performance (browser)Performance (browser)
Performance (browser)
 
Html,CSS & UI/UX design
Html,CSS & UI/UX designHtml,CSS & UI/UX design
Html,CSS & UI/UX design
 
25444215.pptx
25444215.pptx25444215.pptx
25444215.pptx
 
web development
web developmentweb development
web development
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
 
Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG) Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG)
 
Incremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentIncremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend Development
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web components
 
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
 
Introduction to HTML language Web design.pptx
Introduction to HTML language Web design.pptxIntroduction to HTML language Web design.pptx
Introduction to HTML language Web design.pptx
 
Spsbe using js-linkanddisplaytemplates
Spsbe   using js-linkanddisplaytemplatesSpsbe   using js-linkanddisplaytemplates
Spsbe using js-linkanddisplaytemplates
 
ppt.ppt
ppt.pptppt.ppt
ppt.ppt
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Browsers. Magic is inside.

  • 1. Browsers Magic is inside Alex Tokarenko tokarenko@devexperts.com
  • 2. What we will talk about • Browser internal components • Main processes during page load or dynamic changes • Performance tips and tricks • Chrome Devtools in action
  • 3. Why we will talk about it? • Mostly used software in the world • Internet Explorer 90% dominance • Nowadays browsers not a "black box“ - they became opensource
  • 5. Referenced rendering engines All examples will be from source code of WebKit, Blink, Gecko Why? – Because they are open sourced
  • 6. Rendering engine basic flow Parse HTML to construct DOM tree Render tree construction Layout the render tree Paint
  • 8. Parse HTML to construct DOM tree Render tree construction Layout the render tree Paint
  • 9. HTML Parser doings • Parses input HTML tag soup • Fixes web author mistakes • Requests to load resources • Constructs DOM tree
  • 11. HTML Language • HTML approach is very "forgiving“ • HTML is not a context free grammar • Can’t be parsed by XML parser • Can’t be parsed by regular parsers (BNF) • Defined in DTD (Document Type Definition)
  • 12. Error tolerance example #1 WebKit source code: if (m_inStrayTableContent && localName == tableTag) popBlock(tableTag);
  • 13. Error tolerance example #2 • Start with closed tag • Not closed tags at all Handling </BR> in WebKit code: if (t->isCloseTag(brTag) && m_document->inCompatMode()) { reportError(MalformedBRError); t->beginTag = true; }
  • 15. Special parsing algorithm because • Forgiving nature of the language • Historically lack of documentation developers • Huge amount of invalid code HTML parsers 'guesses' the intention of the code author
  • 16. Resources loading during parsing • Scripts • CSS • Other resources
  • 17. Scripts loading VS Page Latency Script is loaded and executed immediately when achieved Parsing halts until script execution
  • 18. Recommendation • Put the script at the end of document • HTML5 defer and async attributes
  • 19. CSS Loading VS Latency Can block scripts execution until loaded
  • 20. Browsers are smart Speculative parsers find resources references to load in parallel threads
  • 21. Parse HTML to construct DOM tree Render tree construction Layout the render tree Paint
  • 22. Rendering tree Holds: • Tree of visual elements in display order • Style information, computed metrics • Shadow DOM tree
  • 24. Out of basic flow • “display:none” elements are excluded • Absolute and fixed position elements • Non visual elements like <head></head>
  • 26. Performance impact • Style is a very large construct • Lookup for matching CSS rule can cause performance issues div div div div { … } • Applying rules is complex
  • 27. Browsers are smart • Style objects can be shared between render objects • Browser collect changes and process them on demand
  • 28. Parse HTML to construct DOM tree Render tree construction Layout the render tree Paint
  • 29. What is Layout process? • Calculation of geometry and position • Flow based model (left-to-right, top-to-bottom) • Coordinate system relative to top left coordinates
  • 30. How Layout Process Works • Parent determines its width • Parent places children with right coordinates • Accumulate children their heights • Caches calculated values
  • 31. Global Layout • Occurs at least ones for whole tree • Happens on global changes (like window resize)
  • 32. Incremental Layout Happens: • When new element added to the tree • When geometric attributes changes
  • 33. Browser is smart Usually changes are batched and done asynchronously However script accessing geometry attributes can force synchronous layout
  • 34. Synchronous layout Synchronous layout demo // Animation loop function update(timestamp) { for(var m = 0; m < movers.length; m++) { movers[m].style.left = ((Math.sin(movers[m].offsetTop + timestamp/1000)+1) * 500) + 'px'; } raf = window.requestAnimationFrame(update); };
  • 35. Painting • Traversing the tree from the root • Global and Incremental paint • Dirty bit system
  • 36. Painting order CSS2 specification defines the order of the painting elements: – background color – background image – border – children – outline
  • 37. What can trigger REcalculations? • Changes style will cause restyle and repaint of the element; • Changes of position will cause relayout and repaint; • Adding a DOM node will cause relayout and repaint of the node. • Major changes will cause invalidation of caches, relayout and repaint
  • 38. Recommendations o Cache style values if possible for read o Change Non-visible element and set it to visible o Use documentFragment or cloned element and then swap it with old one o Use classes instead of inline styles o Try to keep changes lower in the tree
  • 39. How we make a deal with all this stuff?! • Browser dev tools – Timeline – Logs – Heap profiler – Object allocations – CPU Profiler
  • 40. Links • http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/ • http://taligarsiel.com/Projects/howbrowserswork1.htm • https://developers.google.com/chrome-developer-tools/docs/demos/too-much-layout/ • http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/ • https://www.webkit.org/blog/114/webcore-rendering-i-the-basics/ • http://www.chromium.org/blink • http://msdn.microsoft.com/en-us/library/aa741312(v=vs.85).aspx • https://lists.webkit.org/pipermail/webkit-dev/2013-April/024436.html • http://stackoverflow.com/questions/15804169/the-safari-javascript-engine-in-webkit • http://www.html5rocks.com/en/tutorials/speed/script-loading/ • http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html • http://royal.pingdom.com/2013/03/21/browser-wars-2013/ • http://www.html5rocks.com/en/tutorials/memory/effectivemanagement • http://www.html5rocks.com/en/tutorials/speed/static-mem-pools • http://www.html5rocks.com/en/tutorials/performance/mystery/ • http://en.wikipedia.org/wiki/V8_(JavaScript_engine) • http://coding.smashingmagazine.com/2012/11/05/writing-fast-memory-efficient-javascript/ • https://code.google.com/p/v8/
  • 41. Q?
  • 43. Если Вам захотелось присоединиться к команде Devexperts, пишите и звоните нам: Тел.: (812) 438-16-26 E-mail: job@devexperts.com Вакансии: hh.ru и itmozg.ru. Наши новости: devexperts.com и ВКонтакте. Контакты
  • 44. Мы создаем качественное и эффективное ПО для комплексной автоматизации брокерской, биржевой и финансовой деятельности Devexperts
  • 45. Наша команда – это 300 профессионалов в области программирования, тестирования и поддержки ПО