Resource Prioritization
Patrick Meenan
@PatMeenan
slideshare.net/patrickmeenan/resource-prioritization
The Browser
Basic Parser Rules
•Process 1 token at a time
•Stylesheets Block Render
•Non-Async Script tags block Parser/DOM until:
•Pending Stylesheets have loaded
•Script has loaded
Late-Discovered Resources
• Fonts
• Background Images
• Script-injected content
• @import
Dev Control over Prioritization
• Inform browser of late-discovered resources
• <link rel=“preload”…
• Delay images
• <img loading=lazy…
• Boosting priority of async/deferred/late scripts
• <link rel=“preload” as=“script”…
(Simplified) Example
•1 HTML
•1 Stylesheet
•4 Scripts (2 blocking in the head)
•1 Web Font
•13 Images (5 visible)
Optimal Script Loading
Optimal Loading
Start Render
Visually Complete
Worst-Case
Start Render
Visually Complete
HTTP/1.x Prioritization
• 6 Connections per origin
• Pick next-highest for each origin as a connection becomes available
HTTP/2 Prioritization
•All requests sent to server immediately
•Priorities specified in dependency tree
•Any “stream” can depend on another stream
•Peers can be weighted
•Priority changes communicated with a PRIORITY
frame
Prioritizing across connections
External Fonts (before)
3s - Fonts Loaded
Same-origin fonts – supposed to be faster!!!
Start Render
9s – After
2s - Before
Same-origin fonts (correct)
Start Render
1.5s (includes fonts)
Testing for prioritization
https://www.webpagetest.org/http2priorities.html?image=
<url-encoded-image-URL>
Warm-up Connection
Request 30
below-the-fold
Images
(low priority)
Delay until 2 images complete
Sequentially Request 2
in-viewport images
(high priority)
Interrupts in-flight responses
When it goes wrong
Queued behind in-flight
Low-priority requests
Round Robin?
¯_(ツ)_/¯
ishttp2fastyet.com
The Good ✅
• Akamai
• Cloudflare
• Fastly
The Bad ❌
• Amazon Cloudfront
• Cachefly
• CDNetworks
• ChinaCache
• Edgecast
• Highwinds
• Incapsula
• Instart Logic
• KeyCDN
• LeaseWeb CDN
• Level 3
• Limelight
• Medianova
• Netlify
• Rocket CDN
• StackPath/NetDNA/MaxCDN
• Jetpack CDN
• Yottaa
• Zenedge
The Ugly (cloud load balancers) ❌
• Amazon AWS
• Google Cloud
• Microsoft Azure
Testing/Throttling
https://calendar.perfplanet.com/2016/testing-with-realistic-networking-conditions/
Looks Broken Actually Correct
Downloads Look
Concurrent Actually ordered
Performance Monitoring
• Understand what (if any) traffic-shaping is
used
• Watch out for (avoid):
•Dev Tools
•Lighthouse
•Puppeteer
•Proxy
WHY it Goes Wrong
Buffers, buffers everywhere
• Edge server TCP send buffers
• Tune dynamically with TCP_NOTSENT_LOWAT
• Network buffers (bufferbloat)
• BBR Congestion Control
• Upstream application buffers
Loss-based congestion control
What to do?
• Use a “good” CDN
• Or…
What to do?
• Set reasonable default TCP send buffer sizes
• Enable TCP_NOTSENT_LOWAT
• Enable BBR
• Use a Web Server with good prioritization support
Linux
net.core.wmem_max = 250000000
net.ipv4.tcp_wmem = 10240 102400 250000000
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_notsent_lowat = 16384
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
Server-initiated prioritization
HTTP/3 Prioritization?
• Prioritization is an extension, not part of the core spec
• HTTP header-based
• Priority Level + concurrency
• Server override (response header)
• Join the discussion
• https://httpwg.org/
HTTP/3 (and QUIC)
• UDP-based (port 443)
• Moves TCP logic into application layer
• Less OS-level failure modes
• More application responsibility
• Moves loss recovery from per-connection to per-stream
• Will NEVER reach 100% availability
• Treat it as a progressive enhancement
Thank You
Patrick Meenan
@PatMeenan
slideshare.net/patrickmeenan/resource-prioritization

Resource Prioritization