Time is Money!
80-90% of the end-user response time is spent on the frontend. Start here.
| Distinct User Queries | Query refinement | Revenue per User | Any clicks | Satisfaction | Time to Click Increase | |
|---|---|---|---|---|---|---|
| 50ms | - | - | - | - | - | - |
| 200ms | - | - | - | -0.3% | -0.4% | 500ms |
| 500ms | - | -0.6% | -1.2% | -1.0% | -0.9% | 1200ms |
| 1000ms | -0.7% | -0.9% | -1.9% | -2.8% | -1.6% | 1900ms |
| 2000ms | -1.8% | -2.1% | -4.3% | -4.4% | -3.8% | 3100ms |
| Delay | User Reaction |
|---|---|
| 0-100ms | Instant |
| 100-300ms | Feels sluggish |
| 30-1000ms | Machine is working… |
| 1s+ | Mental switch |
| 10s+ | I'll come back later |
Past 12 months
Two main categories:
Global Site Speed Overview: How Fast Are Websites Around The World?
50 performance tricks to make your HTML5 apps and sites faster
| 3G (200 RTT) |
4G (80 RTT) |
|
|---|---|---|
| Control plane | (200-2500) | (50-100) |
| DNS lookup | 200 | 80 |
| TCP Connection | 200 | 80 |
| TLS handshake | (200-400) | (80-160) |
| HTTP Request | 200 | 80 |
What should it do every 16.7ms (60fps)?
function redisplay(images) {
var i;
var container = document.getElementById("container");
container.textContent = ""; // remove all children
for (i = 0;i < images.length; i++) {
var imgEl = document.createElement("img");
imgEl.src = images[i];
container.appendChild(imgElt);
}
}
function resize(incrementSize) {
var i;
var container = document.getElementById("container");
for (i = 0;i < container.childNodes.length; i++) {
var elt = container.childNodes.item(i);
var new_width =
elt.getBoundingClientRect().width
+ incrementSize;
elt.style.width = new_width + "px";
}
}
"The mission of the Web Performance Working Group is to provide methods to enhance aspects of application performance of user agent features and APIs."
We do things like:
.redirectStart, .domainLookupStart, etc..mark(), .measure()document.hidden.requestAnimationFrame.now() (now in sub-milliseconds!)… and we implement them!
| Last Update | Title | Status | Comments |
|---|---|---|---|
| 2012-12-17 | Navigation Timing | Recommendation | |
| 2012-12-17 | High Resolution Time | Recommendation | |
| 2013-10-29 | Page Visibility | Recommendation | |
| 2013-10-31 | User Timing | Proposed Recommendation | |
| 2013-10-31 | Performance Timeline | Proposed Recommendation | |
| 2012-05-22 | Resource Timing | Candidate Recommendation | Need tests and impls |
| 2013-10-31 | Timing control for script-based animations | Candidate Recommendation | Need tests |
| 2013-10-29 | Resource Priorities | First Public Working Draft | In progress |
client-side latency measurements within applications
function onLoad() {
var now = new Date().getTime();
var loadTime =
now-performance.timing.navigationStart;
alert("User-perceived page loading time: "
+ page_load_time);
}
window.performance.now()
client-side latency measurements within applications
function onPlay() {
var resourceList =
window.performance.getEntriesByType("resource");
// for all resources in ResourceList
if (resource.initiatorType == "video") {
alert("autoplay loading time: " +
(performance.now() - resourceList[i].fetchStart));
}
}
video.addEventListener("play", onPlay, false);
setResourceTimingBufferSize)
Timing-Allow-Origin
High precision timestamps for web applications
performance.mark("mark_fully_loaded");
doTask1(); // Some developer code
performance.mark("mark_above_the_fold");
var perfEntries = performance.getEntriesByType("mark");
// for all perfEntries, do something
Determine the current visibility of a page
document.hidden
document.addEventListener('visibilitychange', ...);
function onvisibilitychange() {
if (document.hidden)
video.pause();
else
video.play();
}
Script-based animations where the user agent is in control of limiting the update rate of the animation
function animate(time) {
if (!document.hidden) {
// if visible, draw
canvas.drawImage(myVideoElement, 0, 0);
}
window.requestAnimationFrame(animate);
}
function start() {
window.requestAnimationFrame(animate);
}
<link rel="prerender" href="http://example.com/"/> <link rel="dns-prefetch" href="//example.com"/>
See also preconnect, preload, prerender proposal
hints on the download priority of resources in case of network resource contention or visibility
<img src='foo.png' lazyload>
function unload() {
return beacon("POST", "/log", analyticsData);
}
window.performance.getEntriesByType("error");
Preflight-Cookie: /monitoring.js
???