36
Web Performance Learning's from Velocity Conference- New York Hardik Shah @hardikjs Blog

Web Performance - Learnings from Velocity Conference

Embed Size (px)

DESCRIPTION

Web Performance - These are my Learnings from Velocity Conference.

Citation preview

Page 1: Web Performance - Learnings from Velocity Conference

Web Performance

Learning's from Velocity Conference- New York

Hardik Shah @hardikjs Blog

Page 3: Web Performance - Learnings from Velocity Conference

• Don't optimize anything unless you measure it – Patrick Meenan

• Don’t take performance advice. Test it – Jake Archibald

• Embrace the pain. Become a performance masochist – Tim Kadlec

Favorite Quotes from Velocity

Page 4: Web Performance - Learnings from Velocity Conference

• Testing• User Perception & Working Backwards• Rendering• Performance Culture

4 Things

Page 5: Web Performance - Learnings from Velocity Conference

Testing Performance

• Synthetic Monitoring - Synthetic monitoring is website monitoring that is done using a web browser emulation or scripted real browsers. Behavioral scripts are created to simulate an action or path that customer or end user would take on the site. Those paths are then continuously monitored for performance, such as availability and response times.(wikipedia)

• Real User Monitoring– Passive monitoring technique that records all user

interactions

Page 6: Web Performance - Learnings from Velocity Conference

Synthetic Monitoring

Page 7: Web Performance - Learnings from Velocity Conference

Home Wifi(century link)

Page 8: Web Performance - Learnings from Velocity Conference

AT&T LTE

Page 9: Web Performance - Learnings from Velocity Conference

Company network speed

• Generally 80-130Mbps Download speed

Page 10: Web Performance - Learnings from Velocity Conference

Average US Connection Speed 7.4Mbps

http://www.dslreports.com/shownews/Average-US-Connection-Speed-Now-74-Mbps-123988

We need to get the environment right

Page 11: Web Performance - Learnings from Velocity Conference

Bandwidth is not the only factor… we need to consider Round Trip

Time (RTT) !

https://www.belshe.com/2010/05/24/more-bandwidth-doesnt-matter-much/

Page 12: Web Performance - Learnings from Velocity Conference

Tools to measure performance

• Webpagetest.org• HTTPWatch for Mobile

Other Vendors:- Keynote- Catchpoint- Appurify- AppNeta

Page 13: Web Performance - Learnings from Velocity Conference

Demo of WebPageTest

Page 14: Web Performance - Learnings from Velocity Conference

Speed, Performance & Human Perception

Delay User reaction

0 - 100 ms Instant

100 - 300 ms Feels sluggish

300 - 1000 ms Machine is working...

1 s+ Mental context switch

10 s+ I'll come back later...

Speed, performance and human perception

Page 15: Web Performance - Learnings from Velocity Conference

Is it important to meet user’s perception?

Page 16: Web Performance - Learnings from Velocity Conference

If we were given a budget of 1000ms budget on Mobile…

Let’s work backward and identify where we spend our time

Ilya Grigorik from Google

Page 17: Web Performance - Learnings from Velocity Conference

Input Latency - Hardware

55-120+ ms for hardware to register the touch event!

(ouch...)

Page 18: Web Performance - Learnings from Velocity Conference

Input Latency - Software

Is it a tap, double tap, drag, flick? Let’s wait a bit to find out… To be exact, let’s wait ~300 ms!

● <meta name=”viewport” content=”user-scalable=no”>○ Disables pinch zoom, fires tap event immediately.○ Chrome is working on a more aggressive strategy…

● For older browsers, you can use FastClick to override this behavior.

Page 19: Web Performance - Learnings from Velocity Conference

Firing up the radio

LTE HSPA+ 3G

Idle to connected latency < 100 ms

< 100 ms < 2.5 s

User-plane one-way latency

< 5 ms < 10 ms < 50 ms

Page 20: Web Performance - Learnings from Velocity Conference

Core Network Latency

LTE HSPA+ HSPA EDGE GPRS

AT&T core network latency

40-50 ms 50-200 ms 150-400 ms

600-750 ms

600-750 ms

Page 21: Web Performance - Learnings from Velocity Conference

Short Life of Web Request

• DNS lookup to resolve the hostname to IP address• New TCP connection requiring a full roundtrip to the

server• TLS handshake (not shown) with up to two extra server

roundtrips!• HTTP request requiring a full roundtrip to the server• Server processing time

Page 22: Web Performance - Learnings from Velocity Conference

Let's fetch 40 KB over a new TCP connection

• 5 Mbps connection

• 200 ms roundtrip time

• 100 ms server processing time

• IW10 means ~14KB in first RTT

Page 23: Web Performance - Learnings from Velocity Conference

3G (200 ms RTT)

4G(100 ms RTT)

Control plane (200-2500 ms)

(50-100 ms)

DNS lookup 200 ms 100 ms

TCP Connection 200 ms 100 ms

TLS handshake (200-400 ms)

(100-200 ms)

40 KB HTTP request

200 ms * 3

100 ms * 3

1055 - 4300 ms

555 - 1220 ms

Congrats, we’ve just fetched 40KB!

Input latency

Hardware 55 - 120+ ms

Software 0 - 300 ms

Page 24: Web Performance - Learnings from Velocity Conference

Critical Rendering

• Optimizing Critical Rendering Path– Rendering critical path(html) from the server– Inline Critical CSS in headhttp://www.youtube.com/watch?v=0nwopEYFhko

– Data URI’s http://www.youtube.com/watch?v=8hrtMOGXjAo

– Lazy Load Everything else

Page 25: Web Performance - Learnings from Velocity Conference

Prebrowsing

The browser is already trying to predict and anticipate user activity, but

you have the app-specific insights -- leverage them! Help the browser

with:

1. <link rel="dns-prefetch" href="hostname_to_resolve.com">

Pre-resolve DNS hostnames for assets later in the page! (Most browsers)

2. <link rel="subresource" href="/javascript/myapp.js”>

Initiate early resource fetch for current navigation (Chrome only)

3. <link rel="prefetch" href="/images/big.jpeg”>

Prefetch asset for a future navigation, place in cache… (Most browsers)

4. <link rel="prerender" href="//example.org/next_page.html”>

Prerender page in background tab for future navigation

Page 26: Web Performance - Learnings from Velocity Conference

Rendering without Lumps

• Web Performance have always been about delivering pixels on time, but the target has shifted. Optimizing pure JavaScript (loop, string concatenation, arithmetic) is less relevant, performance gains are to be found in DOM, layout dependencies, and interaction with the GPU – Jake Archibald

Page 27: Web Performance - Learnings from Velocity Conference
Page 28: Web Performance - Learnings from Velocity Conference

Chrome Dev Tools Demo

Page 29: Web Performance - Learnings from Velocity Conference

What works in one browser, may not work in other browsers, so its really important to test before we

commit to a particular solution

Page 30: Web Performance - Learnings from Velocity Conference

Joys of Static Memory JavaScript

• Lots of Garbage collection happening• Garbage collection takes some time• Static memory JS is a technique which involves

preallocating at the start of our app• Object Pool (allocate or deallocate C++ style)

Page 31: Web Performance - Learnings from Velocity Conference

W3C Performance Group

• Navigation and Resource timing (window.performance.timing)

• User timing window.performance.mark(), .measure()

• Page Visibility (document.hidden)• requestAnimationFrame• .now(in sub milliseconds)

Page 32: Web Performance - Learnings from Velocity Conference

What’s Next

• Navigation Timing 2 (Network interface on/off timings)• Pre-render (preemptively fetching and load the specific

resource)• Resource Priorities (lazyload and postpone)• Beacon (asynchronous transfer of data from user agent to web

server)• Diagnostics: Error

window.performance.getEntriesByType(“error”)• Javascript Preflight injection (Monitoring Web Applications)• Display Performance & Async Scroll

– FrameRate of Display paint– Monitor scroll performance of the viewport

Page 33: Web Performance - Learnings from Velocity Conference

Performance Culture

• Everyone is responsible for performance• Publish metrics data as you would publish

financial data• Celebrate performance success as you would

when you get more users or deliver new features

Page 34: Web Performance - Learnings from Velocity Conference

Finally…

Let’s attack performance problems from all the sides. Be Awesome!

Page 35: Web Performance - Learnings from Velocity Conference

References

• Most of the stuff is taken from the presentations(slides) I saw at Velocity.– http://velocityconf.com/velocityny2013/public/sc

hedule/proceedings– http://jakearchibald.com/– http://www.igvita.com/– http://blog.patrickmeenan.com/– http://stevesouders.com/

Page 36: Web Performance - Learnings from Velocity Conference

Thanks!