front end abstractions at facebook

42

Upload: tom-occhino

Post on 27-May-2015

1.999 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Front End Abstractions at Facebook
Page 2: Front End Abstractions at Facebook

Front-end Abstractions

Tom OcchinoJune !"#"

Page 3: Front End Abstractions at Facebook

! Intro

" Resources

# Interaction

$ Rendering

% Conclusion

Agenda

Page 4: Front End Abstractions at Facebook

Intro and some info

Page 5: Front End Abstractions at Facebook

Intro Vocabulary

▪ amped excited, psyched

▪ clowny comical, silly

▪ j0nx stuff, things

▪ lolzy crazy, laugh inducing

Page 6: Front End Abstractions at Facebook

Intro Overview

▪ #" Front-end systems

▪ Server side (PHP) + Client side (JS) integration

▪ High level overview

▪ What is it?

▪ How does it work?

▪ Why did we build it?

Page 7: Front End Abstractions at Facebook

Resource management

Page 8: Front End Abstractions at Facebook

Resources

Haste

Bootloader

Primer

Page 9: Front End Abstractions at Facebook

ResourcesHaste

▪ What is it?

▪ package and dependency management for CSS & JS

Page 10: Front End Abstractions at Facebook

ResourcesHaste

▪ How does it work?

▪ declarative file annotation

▪ @provides single unique identifier

▪ @requires multiple resources

▪ other features

▪ integration

▪ require_static function

▪ analyze_resources script

Page 11: Front End Abstractions at Facebook

ResourcesHaste

▪ Why did we build it?

▪ agility

▪ simplicity

▪ performance

▪ intelligently constructed packages

▪ crazy ass algorithms

▪ no, seriously

Page 12: Front End Abstractions at Facebook

ResourcesBootloader

▪ What is it?

▪ on demand loading and unloading of static resources

▪ includes all required resources

Page 13: Front End Abstractions at Facebook

ResourcesBootloader

▪ How does it work?

▪ loads resources through dynamic script injection

▪ executes callback after all resources are loaded

▪ built to work with Haste

▪ @suggest▪ bootloadEnable

Page 14: Front End Abstractions at Facebook

ResourcesBootloader

▪ Why did we build it?

▪ performance

▪ reduce waste

Page 15: Front End Abstractions at Facebook

ResourcesPrimer

▪ What is it?

▪ That’s the whole file >

Page 16: Front End Abstractions at Facebook

ResourcesPrimer

▪ What is it?

▪ most interactions are simple

▪ GET (click link)

▪ POST (submit form)

▪ aims to be the !"/$" solution

▪ delete tons of boilerplate JavaScript

▪ at one point about #MB of JS on the homepage

Page 17: Front End Abstractions at Facebook

ResourcesPrimer

we had about #MB of JS on the homepage

Page 18: Front End Abstractions at Facebook

ResourcesPrimer

wtf!?

Page 19: Front End Abstractions at Facebook

ResourcesPrimer

▪ How does it work?

▪ small JS file in the <head>

▪ global event listener

▪ looks for attributes like ajaxify

▪ bootload necessary components

▪ perform action when ready

Page 20: Front End Abstractions at Facebook

ResourcesPrimer

▪ Why did we build it?

▪ move JS to bottom of the page (roadrunner)

▪ sick of doing the same crap over and over

▪ we had like, a meg of JS blocking rendering

Page 21: Front End Abstractions at Facebook

Interaction systems

Page 22: Front End Abstractions at Facebook

Interaction

LinkController

PageTransitions

Quickling

PageCache

Page 23: Front End Abstractions at Facebook

Interaction LinkController

▪ What is it?

▪ similar to Primer listens for click events

▪ How does it work?

▪ global mousedown / keydown event

▪ filter out certain clicks

▪ invoke ‘handlers’ for relevant clicks

Page 24: Front End Abstractions at Facebook

Interaction PageTransitions

▪ What is it?

▪ prevent a full page load if we can do something better

▪ How does it work?

▪ register handlers for your component

▪ uri is passed into the handler

▪ look for patterns and handle when possible

▪ kill the default event if handled

Page 25: Front End Abstractions at Facebook

Interaction Quickling

▪ What is it?

▪ a special ‘default’ PageTransition

Page 26: Front End Abstractions at Facebook
Page 27: Front End Abstractions at Facebook

Interaction Quickling

▪ How does it work?

▪ fallback PageTransition handler

▪ simulate browser events Arbiter

▪ store history HistoryManager

▪ appear busy BusyUIManager (!?)

▪ iframe transport

▪ wait cursors

Page 28: Front End Abstractions at Facebook

Interaction Quickling

▪ Drawbacks

▪ css rules over time

▪ memory consumption

▪ complexity

▪ Current Status

▪ IE, FF, Chrome (>%"&)

▪ ~'"& of page loads are through Quickling

▪ up to ~("& reduction in render time

Page 29: Front End Abstractions at Facebook

Interaction PageCache

▪ What is it?

▪ local cache for visited pages

Page 30: Front End Abstractions at Facebook

Interaction PageCache

▪ How does it work?

▪ black magic

▪ built on top of Quickling

▪ cache server responses

▪ pull from cache when there’s a match

▪ replay all new actions

Page 31: Front End Abstractions at Facebook

Interaction PageCache

▪ Drawbacks

▪ complexity

▪ Current Status

▪ enabled for homepage

▪ ~!"& savings on page hits to home

▪ up to )-*x speedup over Quickling alone

Page 32: Front End Abstractions at Facebook

Interaction All Systems

▪ Why did we build them?

▪ performance

▪ full page loads are more expensive than partial

▪ better user experience

▪ especially for things like chat

Page 33: Front End Abstractions at Facebook

InteractionWorldwide TTI

"

#,"""

!,"""

),"""

*,"""

(,"""

p%" p+( p(" p!(

('%&(!

!,$()

",##*

'"$

!,"*#

!,&'(

#,"!*

'$%

!,#$!

",##$

$,(&#

Normal Quicklng PageCache

Footnote: Facebook Internal Data, June !"#"

Page 34: Front End Abstractions at Facebook

Rendering abstractions

Page 35: Front End Abstractions at Facebook

Rendering

Pagelets

Early Flush

BigPipe

Page 36: Front End Abstractions at Facebook

Rendering Pagelets

▪ What are they?

▪ technique for structuring pages

▪ How do they work?

▪ parallel generation

▪ can be refreshed independently

▪ Why did we build it?

▪ flexibility

▪ good design

Page 37: Front End Abstractions at Facebook
Page 38: Front End Abstractions at Facebook

Rendering Early Flush

▪ What is it?

▪ flush the html response in two parts

▪ How does it work?

▪ send the <head> to the browser asap

▪ browser starts downloading resources

▪ server is still generating the page

▪ Why did we build it?

▪ overlap gen+render time

Page 39: Front End Abstractions at Facebook

Rendering BigPipe

Page 40: Front End Abstractions at Facebook

Rendering BigPipe

▪ What is it?

▪ progressive rendering of pages

▪ How does it work?

▪ send down page skeleton

▪ page content in scripts as completed

▪ Why did we build it

▪ LittlePipe was too slow

▪ performance ((."->!.()

Page 41: Front End Abstractions at Facebook

Summary and thoughts