# Life of A Pixel

2 min read, 388 words pixelbrowserfrontend

# Browser facts

  • Both HTML and XML are descendents of SGML specification (opens new window)
  • XML came after HTML
  • Website = 1k+ lines of HTML, CSS and JS (wasm these days)
  • WebContents is sandboxed, so that other webpages cannot access other pages
  • Rendering and pixels, low level APIs?
  • What are the lifecycyle stages of rendering pipeline?
  • shadownDOM vs DOM tree
  • DOM is linked together into a tree DS using pointers
  • What is the js main thread? (opens new window)

# Browser Components

  • User Interface
  • Browser Engine
  • Rendering Engine
  • Netwroking
  • JS Engine, Interpreter
  • UI Backend
  • Data Persistance

Parsing -> Render Tree -> Layout -> Paint

Parsing

Translating a document into a structure that a code can use

  1. Lexical ANalysis
  2. Syntax ANalysis
  3. Lexer (Tokenizer)
  4. Parser

Readymade Examples: Flex, Lex, Yacc, Bison

# Stages

Each stage has its own data structures to work with it.

  1. HTML parsing to low level C++ objects
  2. CSS parsing
  3. JS parsing and execution sent to JS Engine main thread for execution
  4. Visual Gemmetry computation - Layout Object Tree, layoutNG
  5. PaintOps are in memory but have execued yet, Raster executes PaintOps
  6. Rasterization = Paint Objects to in-memory pixel instructions to gpu, openGL, directX, vulcan
  7. Rendered generates Frames/Sec

Layers of Abstraction

  1. DOM
  2. style
  3. layout
  4. paint
  5. raster
  6. GPU
  7. Pixel

But its changing, Animation Frames 60Hertz, even when doing dynamic interaction else jankey

How to do som much compuation 60 times / sec? in rendering pipeline?

Animation Pipelines are optimized using compositing. Instaead of rasterizing the whole area which CSS has changed, create a layer and move the bitmap using GPU

compositor thread gets the first crack at handling things when user interacts/changes browser state. Else, its gets forwarded to js main thread task queue and gets executed whevver its free

# Event Loops

  • shodow DOM
  • stack and heap Memory, web APIs,
  • Queues [Rendering queues and Callback queues]

# Resources

Subscribe to our Newsletter

If you like my work and think it was helpful kindly support my work


Buy Me A Coffee