Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ブラウザの仕組みを完全に理解する / Fully understand how browsers work

やし
January 23, 2020

ブラウザの仕組みを完全に理解する / Fully understand how browsers work

やし

January 23, 2020
Tweet

More Decks by やし

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ΍͠ @yashi848484 • Like: frontend • Love: ΀Α΀Α

    • Recent: ࣾ಺ͷಉ྅ʹ(ͳ͔ͥ)ݹגѻ͍͞ΕΔ
  2. ϒϥ΢βͷओཁͳίϯϙʔωϯτ • User Interface: ΞυϨεόʔ΍໭ΔϘλϯ౳ͷϒϥ΢β্ͷΠϯλʔϑΣʔε • Rendering engine: HTMLΛղੳͯ͠ը໘ʹදࣔ͢Δ΋ͷ(ޙड़) •

    Browser engine: UIͱRendering engineͷ৘ใड͚౉͠ • Networking: httpϦΫΤετ͢Δ • JavaScript engine: jsΛಈ͔͢(ޙड़) • UI backend: νΣοΫϘοΫεͳͲͷඳը • Data persistence: cookieͳͲͷอଘ৔ॴ
  3. Rendering Engine Browser Rendering Engine Chrome(Chromiumܥ) Blink Firefox Gecko +

    Servo Safari Webkit Edge EdgeHTML(࣍ੈ୅͸ଟ෼Blink) IE Trident ※ͨͩ͠ɺiOSͷ৔߹͸શͯWebkit
  4. Rendering: ParseʙDOM • HTMLΛύʔεͯ͠ɺDOMΛ࡞Δ • ͜ͷͱ͖<link><script><img>͕͋Ε͹ɺ֎෦ϦιʔεΛ download͢Δ • inline scriptΛݟ͚ͭͨ৔߹͸ɺઌʹjsίʔυΛload&ղੳ͢

    Δ • js͕DOMߏ଄Λมߋ͢ΔՄೳੑ͕͋ΔͨΊ • <script>ʹasync΍deferΛ෇͚ͯ͜ΕΛճආͰ͖Δ Parse DOM Style Layout Paint
  5. Rendering: Layout • DOM + CSSOM = Layout Tree •

    DOMͱࣅ͍ͯΔ͕ɺϖʔδʹදࣔ͞ΕΔ΋ͷͷΈؚ͕·ΕΔ • ྫ) • display: none→ؚ·Εͳ͍ • visibility: hidden→ؚ·ΕΔ • p::before(content: “Puyo”)→ٖࣅΫϥεͷcontent΋ؚ·ΕΔ • ଞɺrendering͢ΔҐஔͷઈର࠲ඪ΁ͷม׵΋ߦ͏(cssͰ͸਌ཁૉ͔Βͷ૬ର࠲ඪ) Parse DOM Style Layout Paint
  6. Rendering: Activate • ͋ΔίϛοτΛඳը͍ͯ͠Δؒʹɺ࣍ͷίϛοτͷtiling Λߦ͍͍ͨ • ͦͷͨΊɺcompositor threadʹ͸layer tree͕2ͭ͋Δ •

    layer tree͸࠷ॳpending treeɺactivationʹΑΓactive treeͱͳΔ Commit Tiling Raster Activate Draw
  7. TurboFanͱ͸ • V8ʹ͋Δɺ(bytecodeͷ)࠷దԽΛߦ͏ίϯύΠϥ • ʮSea of Nodesʯͱ͍͏֓೦ʹج͍͍ͮͯΔ • https://darksi.de/d.sea-of-nodes/ •

    ৗʹશͯͷίʔυΛ࠷దԽ͢ΔΘ͚Ͱ͸ͳ͍ • ࠷ऴతʹ͸Machine CodeΛੜ੒͢Δ Parse AST Ignition TurboFan Machine Code Byte Code
  8. ࢀߟ • https://v8.dev/docs • https://qiita.com/umashiba/items/8cb47825624c5cb043d6 • https://qiita.com/tsin1rou/items/d4c781a2f25e2b92fa5e • https://qiita.com/pink/items/a54b8cadbe39a06956a9 •

    https://docs.google.com/presentation/d/ 1boPxbgNrTU0ddsc144rcXayGA_WF53k96imRH8Mp34Y/edit#slide=id.g60f92a5151_40_333 • https://gigazine.net/news/20180323-rendering-engine/ • https://developers.google.com/web/updates/2018/09/inside-browser-part1
  9. ࢀߟ • https://efcl.info/2016/03/06/ast-first-step/ • https://docs.google.com/presentation/d/1x2clfAPR9F83cBcmztFRXMnUw3pFX8QGdmXTMcIph4Y/ edit#slide=id.g7a686b0686_0_3 • https://medium.com/@MQuy90/v8-engine-overview-7c965731ced4 • https://speakerdeck.com/brn/source-to-binary-journey-of-v8-javascript-engine

    • https://blog.sessionstack.com/how-javascript-works-inside-the-v8-engine-5-tips-on-how-to-write- optimized-code-ac089e62b12e • https://docs.google.com/presentation/d/1HgDDXBYqCJNasBKBDf9szap1j4q4wnSHhOYpaNy5mHU • https://darksi.de/d.sea-of-nodes/