DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. JavaScript
  4. How Facebook Jacked Up JavaScript Performance

How Facebook Jacked Up JavaScript Performance

Mitch Pronschinske user avatar by
Mitch Pronschinske
·
May. 07, 10 · Interview
Like (0)
Save
Tweet
Share
17.79K Views

Join the DZone community and get the full member experience.

Join For Free
A few months ago we learned about the high-performance PHP compiler, HipHop, which is now open source.  So how did Facebook solve their problems with JavaScript performance when their applications and interface complexity grew dramatically?  At the JavaScript Conference this year, Facebook software engineer Makinde Adeagbo took the audience through Facebook's JS optimization efforts.

Some users probably noticed that Facebook page load times had been getting longer and longer.  Adeagbo said that in 2009, Facebook was very serious about addressing this issue.  In 2006, the web 2.0 giant set a goal for page loads to be under 100ms.  That goal slipped to one second and by mid-2009, pages were taking as long as five seconds to load.  HipHop was smaller than the JavaScript code base at this point.  Facebook developers also needed a solution for JavaScript to get the page loads under control.

Javascript Primer
View more presentations from makinde.


The new goal for the end of 2009 had become 2.5 seconds.  One of the big problems was whole-page-refreshing and scripts that blocked speedy rendering.  First, the team exploited their knowledge of the common interaction types:

  1. User clicks
  2. Sends Async request
  3. Insert/Replace some content

Next, they set up elements similar to this one:

<a href="/ring.php rel="dialog">...</a>


Then a standard listener routine was used to "hijack" these elements, allowing Facebook to update only the sections on a page that needed to be updated.  The two-step technique is outlined in this blog entry:

  • First, build an old-fashioned website that uses hyperlinks and forms to pass information to the server. The server returns whole new pages with each request.
  • Now, use JavaScript to intercept those links and form submissions and pass the information via XMLHttpRequest instead. You can then select which parts of the page need to be updated instead of updating the whole page.

These updates helped all the little labels you see in Facebook ("Like",  "Comments", "Delete", etc.) refresh asynchronously, making load times faster and giving the site more real-time interactivity.  Asynchronous requests carried very little information previously, but now the requests include content.  Since 2009, Facebook has been running without page refreshes by dynamically flipping content and the fragment ID (page transitions).  Just before the end of 2009, Adeagbo says that Facebook met its goal of 2.5 seconds per page load.  

In the process of web building, developers should be aware that it is better NOT to implement a feature unless it is worth risking the good performance of your site(especially for sites with a high degree of complexity, like Facebook).  Adeagbo provides a quote for some clarity on this issue:

"Adding a single line to this file requires great internal reflection and thought.  You must ask yourself if your one line addition is so important, so critical to the success of the company, that it warrants a slowdown for every user on every page load.  Adding a single letter here could cost thousands of man-hours around the world.

That is all."

Adeagbo's presentation was recorded by Ajaxian's [[http://ajaxian.com/archives/facebook-javascript-jsconf]] live blogging notes and the presentation slides on SlideShare.  [http://www.slideshare.net/makinde/javascript-primer]
facebook JavaScript

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Container Security: Don't Let Your Guard Down
  • Tracking Software Architecture Decisions
  • Steel Threads Are a Technique That Will Make You a Better Engineer
  • Monolithic First

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: