@drupflare/spool 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1749 -2
- package/dist/cdn/client.js +1 -0
- package/dist/cdn/location.d.ts +11 -0
- package/dist/cdn/location.js +15 -0
- package/dist/cdn/manifest.json +16 -0
- package/dist/cdn/spool-sw.js +1 -0
- package/dist/client/entry.d.ts +1 -0
- package/dist/client/entry.js +25 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +2 -0
- package/dist/client/lifecycle.d.ts +10 -0
- package/dist/client/lifecycle.js +10 -0
- package/dist/client/loads.d.ts +16 -0
- package/dist/client/loads.js +41 -0
- package/dist/client/register.d.ts +34 -0
- package/dist/client/register.js +58 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/media/embeds.d.ts +59 -0
- package/dist/media/embeds.js +120 -0
- package/dist/media/headers.d.ts +13 -0
- package/dist/media/headers.js +44 -0
- package/dist/media/html.d.ts +27 -0
- package/dist/media/html.js +93 -0
- package/dist/media/image.d.ts +222 -0
- package/dist/media/image.js +413 -0
- package/dist/media/index.d.ts +6 -0
- package/dist/media/index.js +6 -0
- package/dist/media/lazy.d.ts +26 -0
- package/dist/media/lazy.js +74 -0
- package/dist/media/responsive.d.ts +45 -0
- package/dist/media/responsive.js +98 -0
- package/dist/media/video.d.ts +30 -0
- package/dist/media/video.js +75 -0
- package/dist/node/listener.d.ts +19 -0
- package/dist/node/listener.js +76 -0
- package/dist/protocol/artifact.d.ts +54 -0
- package/dist/protocol/artifact.js +79 -0
- package/dist/protocol/assembly.d.ts +34 -0
- package/dist/protocol/assembly.js +72 -0
- package/dist/protocol/beacon.d.ts +59 -0
- package/dist/protocol/beacon.js +86 -0
- package/dist/protocol/collector.d.ts +41 -0
- package/dist/protocol/collector.js +84 -0
- package/dist/protocol/config.d.ts +89 -0
- package/dist/protocol/config.js +13 -0
- package/dist/protocol/envelope.d.ts +47 -0
- package/dist/protocol/envelope.js +162 -0
- package/dist/protocol/errors.d.ts +7 -0
- package/dist/protocol/errors.js +9 -0
- package/dist/protocol/graph.d.ts +81 -0
- package/dist/protocol/graph.js +201 -0
- package/dist/protocol/index.d.ts +19 -0
- package/dist/protocol/index.js +19 -0
- package/dist/protocol/manifest.d.ts +29 -0
- package/dist/protocol/manifest.js +94 -0
- package/dist/protocol/normalise.d.ts +20 -0
- package/dist/protocol/normalise.js +29 -0
- package/dist/protocol/pattern.d.ts +12 -0
- package/dist/protocol/pattern.js +82 -0
- package/dist/protocol/provision.d.ts +100 -0
- package/dist/protocol/provision.js +105 -0
- package/dist/protocol/route.d.ts +179 -0
- package/dist/protocol/route.js +135 -0
- package/dist/protocol/sync.d.ts +31 -0
- package/dist/protocol/sync.js +87 -0
- package/dist/protocol/tag.d.ts +12 -0
- package/dist/protocol/tag.js +26 -0
- package/dist/protocol/template/compile.d.ts +35 -0
- package/dist/protocol/template/compile.js +82 -0
- package/dist/protocol/template/interpret.d.ts +9 -0
- package/dist/protocol/template/interpret.js +82 -0
- package/dist/protocol/vector.d.ts +32 -0
- package/dist/protocol/vector.js +56 -0
- package/dist/protocol/view.d.ts +110 -0
- package/dist/protocol/view.js +201 -0
- package/dist/proxy/dictionary.d.ts +58 -0
- package/dist/proxy/dictionary.js +197 -0
- package/dist/proxy/eligible.d.ts +45 -0
- package/dist/proxy/eligible.js +96 -0
- package/dist/proxy/index.d.ts +5 -0
- package/dist/proxy/index.js +5 -0
- package/dist/proxy/proxy.d.ts +133 -0
- package/dist/proxy/proxy.js +507 -0
- package/dist/proxy/purge.d.ts +10 -0
- package/dist/proxy/purge.js +66 -0
- package/dist/proxy/tags.d.ts +8 -0
- package/dist/proxy/tags.js +36 -0
- package/dist/report/derive.d.ts +223 -0
- package/dist/report/derive.js +494 -0
- package/dist/report/economics.d.ts +14 -0
- package/dist/report/economics.js +24 -0
- package/dist/report/index.d.ts +9 -0
- package/dist/report/index.js +9 -0
- package/dist/report/inputs.d.ts +141 -0
- package/dist/report/inputs.js +216 -0
- package/dist/report/ledger.d.ts +169 -0
- package/dist/report/ledger.js +278 -0
- package/dist/report/measurement.d.ts +48 -0
- package/dist/report/measurement.js +117 -0
- package/dist/report/model.d.ts +42 -0
- package/dist/report/model.js +74 -0
- package/dist/report/thirdparty.d.ts +62 -0
- package/dist/report/thirdparty.js +107 -0
- package/dist/report/traffic.d.ts +140 -0
- package/dist/report/traffic.js +228 -0
- package/dist/report/trim.d.ts +81 -0
- package/dist/report/trim.js +105 -0
- package/dist/server/beacon.d.ts +20 -0
- package/dist/server/beacon.js +47 -0
- package/dist/server/embedded.d.ts +6 -0
- package/dist/server/embedded.js +6 -0
- package/dist/server/ga4.d.ts +70 -0
- package/dist/server/ga4.js +165 -0
- package/dist/server/identity.d.ts +12 -0
- package/dist/server/identity.js +17 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +7 -0
- package/dist/server/sink.d.ts +56 -0
- package/dist/server/sink.js +133 -0
- package/dist/server/size.d.ts +7 -0
- package/dist/server/size.js +18 -0
- package/dist/server/spool.d.ts +97 -0
- package/dist/server/spool.js +463 -0
- package/dist/server/stub.d.ts +9 -0
- package/dist/server/stub.js +19 -0
- package/dist/server/sync.d.ts +12 -0
- package/dist/server/sync.js +48 -0
- package/dist/server/work.d.ts +22 -0
- package/dist/server/work.js +30 -0
- package/dist/stores/durable-object.d.ts +19 -0
- package/dist/stores/durable-object.js +53 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/index.js +2 -0
- package/dist/stores/memory.d.ts +4 -0
- package/dist/stores/memory.js +10 -0
- package/dist/stores/version-store.d.ts +11 -0
- package/dist/stores/version-store.js +1 -0
- package/dist/sw/analytics.d.ts +81 -0
- package/dist/sw/analytics.js +275 -0
- package/dist/sw/collect.d.ts +8 -0
- package/dist/sw/collect.js +33 -0
- package/dist/sw/core.d.ts +1 -0
- package/dist/sw/core.js +3 -0
- package/dist/sw/freshness.d.ts +15 -0
- package/dist/sw/freshness.js +20 -0
- package/dist/sw/graph/index.d.ts +67 -0
- package/dist/sw/graph/index.js +170 -0
- package/dist/sw/graph/invalidate.d.ts +23 -0
- package/dist/sw/graph/invalidate.js +109 -0
- package/dist/sw/graph/projections.d.ts +7 -0
- package/dist/sw/graph/projections.js +9 -0
- package/dist/sw/graph/records.d.ts +7 -0
- package/dist/sw/graph/records.js +9 -0
- package/dist/sw/graph/store.d.ts +32 -0
- package/dist/sw/graph/store.js +52 -0
- package/dist/sw/idb.d.ts +8 -0
- package/dist/sw/idb.js +117 -0
- package/dist/sw/index.d.ts +2 -0
- package/dist/sw/index.js +1 -0
- package/dist/sw/partition.d.ts +21 -0
- package/dist/sw/partition.js +137 -0
- package/dist/sw/policy.d.ts +8 -0
- package/dist/sw/policy.js +24 -0
- package/dist/sw/provision.d.ts +39 -0
- package/dist/sw/provision.js +61 -0
- package/dist/sw/render.d.ts +21 -0
- package/dist/sw/render.js +53 -0
- package/dist/sw/replica.d.ts +77 -0
- package/dist/sw/replica.js +299 -0
- package/dist/sw/router.d.ts +42 -0
- package/dist/sw/router.js +48 -0
- package/dist/sw/routing.d.ts +23 -0
- package/dist/sw/routing.js +48 -0
- package/dist/sw/runtime.d.ts +112 -0
- package/dist/sw/runtime.js +1070 -0
- package/dist/sw/scheduler.d.ts +83 -0
- package/dist/sw/scheduler.js +149 -0
- package/dist/sw/seal.d.ts +37 -0
- package/dist/sw/seal.js +183 -0
- package/dist/sw/serve.d.ts +15 -0
- package/dist/sw/serve.js +63 -0
- package/dist/sw/shadow.d.ts +16 -0
- package/dist/sw/shadow.js +27 -0
- package/dist/sw/static.d.ts +17 -0
- package/dist/sw/static.js +81 -0
- package/dist/sw/storage.d.ts +64 -0
- package/dist/sw/storage.js +34 -0
- package/dist/sw/thirdparty.d.ts +17 -0
- package/dist/sw/thirdparty.js +36 -0
- package/dist/trim/css.d.ts +38 -0
- package/dist/trim/css.js +328 -0
- package/dist/trim/index.d.ts +3 -0
- package/dist/trim/index.js +3 -0
- package/dist/trim/manifest.d.ts +67 -0
- package/dist/trim/manifest.js +134 -0
- package/dist/trim/tokens.d.ts +47 -0
- package/dist/trim/tokens.js +142 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/package.json +150 -5
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { CONTAMINATION_MS_PER_S, isContaminated, median, quantile, spread } from './derive.js';
|
|
2
|
+
import { attributionalJoules } from './model.js';
|
|
3
|
+
const EMBED_HOSTS = {
|
|
4
|
+
'www.youtube.com': 'youtube',
|
|
5
|
+
'youtube.com': 'youtube',
|
|
6
|
+
'www.youtube-nocookie.com': 'youtube',
|
|
7
|
+
'youtube-nocookie.com': 'youtube',
|
|
8
|
+
'player.vimeo.com': 'vimeo'
|
|
9
|
+
};
|
|
10
|
+
/** the bytes a WebP of each image saves: `native` is the file at its own size, `ceiling` the width ceiling, `resized` the rendered width */
|
|
11
|
+
export function imageSavings(rows) {
|
|
12
|
+
let format = 0;
|
|
13
|
+
let resize = 0;
|
|
14
|
+
let lossless = 0;
|
|
15
|
+
for (const row of rows) {
|
|
16
|
+
const arms = row.arms;
|
|
17
|
+
if (!arms?.native)
|
|
18
|
+
continue;
|
|
19
|
+
const ceiling = arms.ceiling?.bytes ?? arms.native.bytes;
|
|
20
|
+
const base = Math.min(row.bytes, ceiling);
|
|
21
|
+
format += row.bytes - base;
|
|
22
|
+
resize += base - Math.min(base, arms.resized?.bytes ?? base);
|
|
23
|
+
if (arms.lossless)
|
|
24
|
+
lossless += Math.max(0, base - arms.lossless.bytes);
|
|
25
|
+
}
|
|
26
|
+
return { format, resize, lossless };
|
|
27
|
+
}
|
|
28
|
+
/** the levers of the image-crawl corpus: the first views of the desktop profile, one entry per page */
|
|
29
|
+
export function crawlLevers(rows) {
|
|
30
|
+
const all = rows;
|
|
31
|
+
const pages = all.filter((r) => r.kind === 'page' &&
|
|
32
|
+
r.profile === 'desktop' &&
|
|
33
|
+
r.variant === 'original' &&
|
|
34
|
+
r.ok === true);
|
|
35
|
+
const images = all.filter((r) => r.kind === 'image' && r.profile === 'desktop');
|
|
36
|
+
const embeds = all.filter((r) => r.kind === 'embed');
|
|
37
|
+
const facade = (provider) => {
|
|
38
|
+
const row = embeds.find((e) => e.provider === provider && e.arm === 'facade');
|
|
39
|
+
return row ? row.bytes + row.docBytes : 0;
|
|
40
|
+
};
|
|
41
|
+
const key = (r) => `${r.site}|${r.page}`;
|
|
42
|
+
const byPage = new Map();
|
|
43
|
+
for (const image of images)
|
|
44
|
+
byPage.set(key(image), [...(byPage.get(key(image)) ?? []), image]);
|
|
45
|
+
const sites = pages.map((p) => p.site);
|
|
46
|
+
const per = (f) => pages.map(f);
|
|
47
|
+
const embedSaved = (page) => page.iframes.reduce((sum, frame) => {
|
|
48
|
+
const provider = EMBED_HOSTS[frame.host];
|
|
49
|
+
return provider ? sum + Math.max(0, frame.bytes - facade(provider)) : sum;
|
|
50
|
+
}, 0);
|
|
51
|
+
const idle = (page) => page.videoTags.length > 0 && page.videoTags.every((t) => !t.autoplay);
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
id: 'images-format',
|
|
55
|
+
status: 'default',
|
|
56
|
+
corpus: 'crawl',
|
|
57
|
+
sites,
|
|
58
|
+
bytes: per((p) => imageSavings(byPage.get(key(p)) ?? []).format)
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'images-resize',
|
|
62
|
+
status: 'default',
|
|
63
|
+
corpus: 'crawl',
|
|
64
|
+
sites,
|
|
65
|
+
bytes: per((p) => imageSavings(byPage.get(key(p)) ?? []).resize)
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: 'video-preload',
|
|
69
|
+
status: 'default',
|
|
70
|
+
corpus: 'crawl',
|
|
71
|
+
sites,
|
|
72
|
+
bytes: per((p) => (idle(p) ? p.videoBytes : 0))
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'video-defer',
|
|
76
|
+
status: 'option',
|
|
77
|
+
corpus: 'crawl',
|
|
78
|
+
sites,
|
|
79
|
+
bytes: per((p) => (idle(p) ? 0 : p.videoBytes))
|
|
80
|
+
},
|
|
81
|
+
{ id: 'embeds', status: 'option', corpus: 'crawl', sites, bytes: per(embedSaved) }
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
/** bytes of image data a visit that never scrolls does not load when `loading="lazy"` is on, by page */
|
|
85
|
+
export function lazyUnscrolled(rows, profile = 'desktop') {
|
|
86
|
+
const pages = rows.filter((r) => r.kind === 'page' && r.profile === profile && r.ok === true);
|
|
87
|
+
const original = new Map(pages.filter((p) => p.variant === 'original').map((p) => [`${p.site}|${p.page}`, p]));
|
|
88
|
+
const pairs = pages
|
|
89
|
+
.filter((p) => p.variant === 'lazy')
|
|
90
|
+
.flatMap((lazy) => {
|
|
91
|
+
const base = original.get(`${lazy.site}|${lazy.page}`);
|
|
92
|
+
return base ? [{ base, lazy }] : [];
|
|
93
|
+
});
|
|
94
|
+
const lcpImages = pairs.filter((p) => p.lazy.lcp?.tag === 'IMG');
|
|
95
|
+
return {
|
|
96
|
+
pairs: pairs.length,
|
|
97
|
+
sites: pairs.map((p) => p.base.site),
|
|
98
|
+
bytes: pairs.map((p) => Math.max(0, p.base.imageBytesLoad - p.lazy.imageBytesLoad)),
|
|
99
|
+
baseLoad: pairs.map((p) => p.base.imageBytesLoad),
|
|
100
|
+
lazyLoad: pairs.map((p) => p.lazy.imageBytesLoad),
|
|
101
|
+
lcpImagePages: lcpImages.length,
|
|
102
|
+
lcpLazyPages: lcpImages.filter((p) => p.lazy.lcp?.loading === 'lazy' && p.base.lcp?.loading !== 'lazy').length
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** the levers of the trim corpus: the first views of internal pages of the Drupal sites */
|
|
106
|
+
export function trimLevers(trimmed, crawl) {
|
|
107
|
+
const trimSites = trimmed;
|
|
108
|
+
const aggSites = crawl;
|
|
109
|
+
const internal = (sites) => sites.flatMap((s) => s.pages.filter((p) => p.kind === 'internal').map((p) => ({ site: s.site, page: p })));
|
|
110
|
+
const css = internal(trimSites);
|
|
111
|
+
const agg = internal(aggSites).filter((x) => x.page.ok === true && x.page.newAgg);
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
id: 'css-trim',
|
|
115
|
+
status: 'option',
|
|
116
|
+
corpus: 'trim',
|
|
117
|
+
sites: css.map((x) => x.site),
|
|
118
|
+
bytes: css.map((x) => x.page.saved.br5Saved)
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 'aggregate-dictionary',
|
|
122
|
+
status: 'max',
|
|
123
|
+
corpus: 'trim',
|
|
124
|
+
sites: agg.map((x) => x.site),
|
|
125
|
+
bytes: agg.map((x) => {
|
|
126
|
+
const a = x.page.newAgg;
|
|
127
|
+
return a.zstdAlone > 0 ? a.transfer * Math.max(0, 1 - a.zstdDict / a.zstdAlone) : 0;
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
/** {@link LeverStats} of a lever's per-page bytes, or null for an empty corpus */
|
|
133
|
+
export function leverStats(sites, bytes) {
|
|
134
|
+
if (bytes.length === 0)
|
|
135
|
+
return null;
|
|
136
|
+
const saving = bytes.filter((b) => b > 0);
|
|
137
|
+
const perSite = new Map();
|
|
138
|
+
bytes.forEach((b, i) => perSite.set(sites[i], [...(perSite.get(sites[i]) ?? []), b]));
|
|
139
|
+
const mean = (xs) => xs.reduce((s, x) => s + x, 0) / xs.length;
|
|
140
|
+
return {
|
|
141
|
+
pages: bytes.length,
|
|
142
|
+
withSaving: saving.length,
|
|
143
|
+
medianPage: quantile(bytes, 0.5),
|
|
144
|
+
medianEligible: saving.length > 0 ? quantile(saving, 0.5) : null,
|
|
145
|
+
medianSite: median([...perSite.values()].map(mean)),
|
|
146
|
+
mean: mean(bytes)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** the bytes of several levers added page by page; the levers must come from one corpus and one page order */
|
|
150
|
+
export function addLevers(levers) {
|
|
151
|
+
const first = levers[0];
|
|
152
|
+
if (!first)
|
|
153
|
+
return null;
|
|
154
|
+
return {
|
|
155
|
+
sites: first.sites,
|
|
156
|
+
bytes: first.bytes.map((_, i) => levers.reduce((sum, l) => sum + (l.bytes[i] ?? 0), 0))
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** the dictionary choices the `dictionary-size` rig measures; see that rig for what each one is */
|
|
160
|
+
export const DICTIONARY_ARMS = [
|
|
161
|
+
'oracle',
|
|
162
|
+
'browser',
|
|
163
|
+
'serverVisit',
|
|
164
|
+
'serverHeld',
|
|
165
|
+
'serverOut'
|
|
166
|
+
];
|
|
167
|
+
/**
|
|
168
|
+
* The savings of each dictionary choice in a `dictionary-size` reading, for `dcz` (zstd) and `dcb`
|
|
169
|
+
* (brotli). A file the choice gives no dictionary, or whose delta is not smaller than brotli 11,
|
|
170
|
+
* saves nothing.
|
|
171
|
+
*/
|
|
172
|
+
export function dictionaryArms(rows) {
|
|
173
|
+
const files = rows.filter((r) => r.kind === 'file');
|
|
174
|
+
const stat = (arm, codec) => {
|
|
175
|
+
const saved = (f) => {
|
|
176
|
+
const size = f[arm]?.[codec];
|
|
177
|
+
return size == null ? 0 : Math.max(0, f.br11 - size);
|
|
178
|
+
};
|
|
179
|
+
const share = (group) => {
|
|
180
|
+
const plain = group.reduce((s, f) => s + f.br11, 0);
|
|
181
|
+
return plain > 0 ? group.reduce((s, f) => s + saved(f), 0) / plain : 0;
|
|
182
|
+
};
|
|
183
|
+
const bySite = new Map();
|
|
184
|
+
const byPage = new Map();
|
|
185
|
+
for (const f of files) {
|
|
186
|
+
bySite.set(f.site, [...(bySite.get(f.site) ?? []), f]);
|
|
187
|
+
if (f.pageKind === 'internal') {
|
|
188
|
+
const key = `${f.site}|${f.page}`;
|
|
189
|
+
byPage.set(key, [...(byPage.get(key) ?? []), f]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const pages = [...byPage.values()];
|
|
193
|
+
return {
|
|
194
|
+
medianSite: median([...bySite.values()].map(share)),
|
|
195
|
+
pooled: share(files),
|
|
196
|
+
pages: pages.length,
|
|
197
|
+
medianPageBytes: median(pages.map((p) => p.reduce((s, f) => s + saved(f), 0))),
|
|
198
|
+
pagesOver5: pages.filter((p) => share(p) > 0.05).length
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const arms = {};
|
|
202
|
+
for (const arm of DICTIONARY_ARMS)
|
|
203
|
+
arms[arm] = { zstd: stat(arm, 'zstd'), br: stat(arm, 'br') };
|
|
204
|
+
return {
|
|
205
|
+
sites: new Set(files.map((f) => f.site)).size,
|
|
206
|
+
files: files.length,
|
|
207
|
+
br11Bytes: files.reduce((s, f) => s + f.br11, 0),
|
|
208
|
+
arms
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const windowSeconds = (row) => row.elapsedMs / 1000;
|
|
212
|
+
const timed = (rows) => rows.filter((r) => typeof r.elapsedMs === 'number' && r.elapsedMs > 0);
|
|
213
|
+
const tally = (counts, arm) => (counts[String(arm)] ??= { kept: 0, dropped: 0, idleControl: 0 });
|
|
214
|
+
/** kept and dropped windows per arm under the contamination limit; a row with no length (a probe) is not a window */
|
|
215
|
+
export function windowCounts(rows, limit = CONTAMINATION_MS_PER_S) {
|
|
216
|
+
const counts = {};
|
|
217
|
+
for (const row of timed(rows)) {
|
|
218
|
+
tally(counts, row.arm)[isContaminated(row, limit) ? 'dropped' : 'kept']++;
|
|
219
|
+
}
|
|
220
|
+
return counts;
|
|
221
|
+
}
|
|
222
|
+
/** the idle windows of a round may differ by this factor, largest over smallest, before the round is dropped */
|
|
223
|
+
export const IDLE_AGREEMENT = 1.25;
|
|
224
|
+
/**
|
|
225
|
+
* Package watts per arm of an idle-activity reading. A window is dropped when other containers used
|
|
226
|
+
* more than `limit` ms of CPU per second. The rig cannot see a host process or a container that
|
|
227
|
+
* stopped inside a window, so the three idle windows of each round also act as a control: when the
|
|
228
|
+
* largest of them is over {@link IDLE_AGREEMENT} times the smallest, the whole round is dropped. An
|
|
229
|
+
* arm with no kept window is null.
|
|
230
|
+
*/
|
|
231
|
+
export function activityFigures(rows, limit = CONTAMINATION_MS_PER_S) {
|
|
232
|
+
const counts = {};
|
|
233
|
+
const watts = (row) => row.pkgJ / windowSeconds(row);
|
|
234
|
+
const calm = timed(rows).filter((row) => {
|
|
235
|
+
const contaminated = isContaminated(row, limit);
|
|
236
|
+
if (contaminated)
|
|
237
|
+
tally(counts, row.arm).dropped++;
|
|
238
|
+
return !contaminated;
|
|
239
|
+
});
|
|
240
|
+
const idleByRound = new Map();
|
|
241
|
+
for (const row of calm) {
|
|
242
|
+
if (row.arm === 'idle') {
|
|
243
|
+
idleByRound.set(row.round, [
|
|
244
|
+
...(idleByRound.get(row.round) ?? []),
|
|
245
|
+
watts(row)
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const noisy = [...idleByRound]
|
|
250
|
+
.filter(([, w]) => w.length > 1 && Math.max(...w) > IDLE_AGREEMENT * Math.min(...w))
|
|
251
|
+
.map(([round]) => round);
|
|
252
|
+
const kept = calm.filter((row) => {
|
|
253
|
+
const drop = noisy.includes(row.round);
|
|
254
|
+
tally(counts, row.arm)[drop ? 'idleControl' : 'kept']++;
|
|
255
|
+
return !drop;
|
|
256
|
+
});
|
|
257
|
+
const idleRound = new Map([...idleByRound].filter(([round]) => !noisy.includes(round)).map(([r, w]) => [r, median(w)]));
|
|
258
|
+
const idleWatts = idleRound.size > 0 ? spread([...idleRound.values()]) : null;
|
|
259
|
+
const arms = {};
|
|
260
|
+
for (const name of new Set(timed(rows).map((row) => String(row.arm)))) {
|
|
261
|
+
if (name === 'idle')
|
|
262
|
+
continue;
|
|
263
|
+
const mine = kept.filter((row) => row.arm === name && idleRound.has(row.round));
|
|
264
|
+
arms[name] =
|
|
265
|
+
mine.length === 0
|
|
266
|
+
? null
|
|
267
|
+
: {
|
|
268
|
+
windows: mine.length,
|
|
269
|
+
watts: spread(mine.map(watts)),
|
|
270
|
+
extraWatts: spread(mine.map((row) => watts(row) - idleRound.get(row.round)))
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return { idleWatts, noisyRounds: noisy.sort((a, b) => a - b), counts, arms };
|
|
274
|
+
}
|
|
275
|
+
/** attributional joules for `bytes` (the same SWD v4 rate as the headline, no origin term: these are the same requests with fewer bytes) */
|
|
276
|
+
export const ledgerJoules = (bytes) => attributionalJoules(bytes);
|
|
277
|
+
/** megawatt-hours a year when `perView` joules are saved on a share of `views` views */
|
|
278
|
+
export const ledgerMWh = (perView, views, share) => (perView * views * share) / 3.6e9;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Layer } from './inputs.js';
|
|
2
|
+
/** the rigs that write to `measurements/<rig>/`, one folder each */
|
|
3
|
+
export declare const RIGS: readonly ["repeat-nav", "on-wire", "zero-network", "device-cpu", "rapl", "iphone", "payload", "trim", "link-assets", "image-crawl", "dictionary-size"];
|
|
4
|
+
/** one of {@link RIGS} */
|
|
5
|
+
export type Rig = (typeof RIGS)[number];
|
|
6
|
+
/** the format version {@link parseMeasurement} reads */
|
|
7
|
+
export declare const MEASUREMENT_SCHEMA = 1;
|
|
8
|
+
/** one window or navigation as the rig recorded it: raw quantities, never a per-view figure */
|
|
9
|
+
export type Row = Record<string, unknown>;
|
|
10
|
+
/** one run of one rig, as stored in `measurements/<rig>/<date>[-<experiment>].json` */
|
|
11
|
+
export type Measurement = {
|
|
12
|
+
schema: typeof MEASUREMENT_SCHEMA;
|
|
13
|
+
rig: Rig;
|
|
14
|
+
/** the run date, UTC, `YYYY-MM-DD` */
|
|
15
|
+
date: string;
|
|
16
|
+
layer: Extract<Layer, 'L1'>;
|
|
17
|
+
/** what the run answers */
|
|
18
|
+
question: string;
|
|
19
|
+
/** what read the numbers */
|
|
20
|
+
instrument: string;
|
|
21
|
+
/** the hardware, with at least a `name` */
|
|
22
|
+
machine: Record<string, string | number>;
|
|
23
|
+
software: Record<string, string>;
|
|
24
|
+
/** windows, rounds, arm order, pacing and any emulation */
|
|
25
|
+
method: Record<string, unknown>;
|
|
26
|
+
/** rules for rows a reader must drop, with the reason */
|
|
27
|
+
exclusions: string[];
|
|
28
|
+
rows: Row[];
|
|
29
|
+
};
|
|
30
|
+
/** every problem a file has, so one read reports them all */
|
|
31
|
+
export declare class MeasurementError extends Error {
|
|
32
|
+
readonly problems: string[];
|
|
33
|
+
constructor(problems: string[], source?: string);
|
|
34
|
+
}
|
|
35
|
+
/** what a published file must not carry: the kinds of id or address found in `text` */
|
|
36
|
+
export declare function findLeaks(text: string): string[];
|
|
37
|
+
/** the problems with one measurement document, empty when it is valid */
|
|
38
|
+
export declare function measurementProblems(input: unknown): string[];
|
|
39
|
+
/** the document as a {@link Measurement}, or a {@link MeasurementError} naming every problem */
|
|
40
|
+
export declare function parseMeasurement(input: unknown, source?: string): Measurement;
|
|
41
|
+
/** {@link parseMeasurement} over JSON text, which also refuses ids and addresses a file must not carry */
|
|
42
|
+
export declare function parseMeasurementText(text: string, source?: string): Measurement;
|
|
43
|
+
/** where a run is stored, relative to `measurements/`: `<rig>/<date>[-<experiment>].json` */
|
|
44
|
+
export declare function measurementPath(measurement: Pick<Measurement, 'rig' | 'date'>, experiment?: string): string;
|
|
45
|
+
/** whether a path under `measurements/` matches the rig and date inside the file */
|
|
46
|
+
export declare function pathMatches(path: string, measurement: Pick<Measurement, 'rig' | 'date'>): boolean;
|
|
47
|
+
/** the file text a rig writes: tab indented, one trailing newline, `schema` first */
|
|
48
|
+
export declare function serialiseMeasurement(measurement: Omit<Measurement, 'schema'>): string;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** the rigs that write to `measurements/<rig>/`, one folder each */
|
|
2
|
+
export const RIGS = [
|
|
3
|
+
'repeat-nav',
|
|
4
|
+
'on-wire',
|
|
5
|
+
'zero-network',
|
|
6
|
+
'device-cpu',
|
|
7
|
+
'rapl',
|
|
8
|
+
'iphone',
|
|
9
|
+
'payload',
|
|
10
|
+
'trim',
|
|
11
|
+
'link-assets',
|
|
12
|
+
'image-crawl',
|
|
13
|
+
'dictionary-size'
|
|
14
|
+
];
|
|
15
|
+
/** the format version {@link parseMeasurement} reads */
|
|
16
|
+
export const MEASUREMENT_SCHEMA = 1;
|
|
17
|
+
/** every problem a file has, so one read reports them all */
|
|
18
|
+
export class MeasurementError extends Error {
|
|
19
|
+
problems;
|
|
20
|
+
constructor(problems, source) {
|
|
21
|
+
super(`${source ? `${source}: ` : ''}${problems.join('; ')}`);
|
|
22
|
+
this.name = 'MeasurementError';
|
|
23
|
+
this.problems = problems;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
27
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
28
|
+
const isText = (value) => typeof value === 'string' && value.trim() !== '';
|
|
29
|
+
/** a device id, a container id used as a key, or an address that is not loopback */
|
|
30
|
+
const LEAKS = [
|
|
31
|
+
['a device id', /\b0000[0-9A-F]{4}-[0-9A-F]{16}\b/],
|
|
32
|
+
['a container id', /"[0-9a-f]{12}":/],
|
|
33
|
+
['an IP address', /\b(?!127\.0\.0\.1\b)(?:\d{1,3}\.){3}\d{1,3}\b/]
|
|
34
|
+
];
|
|
35
|
+
/** what a published file must not carry: the kinds of id or address found in `text` */
|
|
36
|
+
export function findLeaks(text) {
|
|
37
|
+
return LEAKS.filter(([, pattern]) => pattern.test(text)).map(([name]) => name);
|
|
38
|
+
}
|
|
39
|
+
function validDate(text) {
|
|
40
|
+
if (!DATE.test(text))
|
|
41
|
+
return false;
|
|
42
|
+
const date = new Date(`${text}T00:00:00Z`);
|
|
43
|
+
return !Number.isNaN(date.getTime()) && date.toISOString().startsWith(text);
|
|
44
|
+
}
|
|
45
|
+
/** the problems with one measurement document, empty when it is valid */
|
|
46
|
+
export function measurementProblems(input) {
|
|
47
|
+
if (!isRecord(input))
|
|
48
|
+
return ['the file is not a JSON object'];
|
|
49
|
+
const problems = [];
|
|
50
|
+
if (input.schema !== MEASUREMENT_SCHEMA)
|
|
51
|
+
problems.push(`schema must be ${MEASUREMENT_SCHEMA}`);
|
|
52
|
+
if (!RIGS.includes(input.rig))
|
|
53
|
+
problems.push(`rig must be one of ${RIGS.join(', ')}`);
|
|
54
|
+
if (typeof input.date !== 'string' || !validDate(input.date)) {
|
|
55
|
+
problems.push('date must be a real UTC date as YYYY-MM-DD');
|
|
56
|
+
}
|
|
57
|
+
if (input.layer !== 'L1')
|
|
58
|
+
problems.push('layer must be L1, readings here are measured');
|
|
59
|
+
for (const key of ['question', 'instrument']) {
|
|
60
|
+
if (!isText(input[key]))
|
|
61
|
+
problems.push(`${key} must be a non-empty string`);
|
|
62
|
+
}
|
|
63
|
+
const { machine, software } = input;
|
|
64
|
+
if (!isRecord(machine) || !isText(machine.name))
|
|
65
|
+
problems.push('machine needs a name');
|
|
66
|
+
else if (!Object.values(machine).every((v) => typeof v === 'string' || typeof v === 'number')) {
|
|
67
|
+
problems.push('machine values must be strings or numbers');
|
|
68
|
+
}
|
|
69
|
+
if (!isRecord(software) || !Object.values(software).every((v) => typeof v === 'string')) {
|
|
70
|
+
problems.push('software must map names to version strings');
|
|
71
|
+
}
|
|
72
|
+
if (!isRecord(input.method))
|
|
73
|
+
problems.push('method must be an object');
|
|
74
|
+
const { exclusions } = input;
|
|
75
|
+
if (!Array.isArray(exclusions) || !exclusions.every(isText)) {
|
|
76
|
+
problems.push('exclusions must be a list of reasons');
|
|
77
|
+
}
|
|
78
|
+
const { rows } = input;
|
|
79
|
+
if (!Array.isArray(rows) || rows.length === 0 || !rows.every(isRecord)) {
|
|
80
|
+
problems.push('rows must be a non-empty list of objects');
|
|
81
|
+
}
|
|
82
|
+
return problems;
|
|
83
|
+
}
|
|
84
|
+
/** the document as a {@link Measurement}, or a {@link MeasurementError} naming every problem */
|
|
85
|
+
export function parseMeasurement(input, source) {
|
|
86
|
+
const problems = measurementProblems(input);
|
|
87
|
+
if (problems.length > 0)
|
|
88
|
+
throw new MeasurementError(problems, source);
|
|
89
|
+
return input;
|
|
90
|
+
}
|
|
91
|
+
/** {@link parseMeasurement} over JSON text, which also refuses ids and addresses a file must not carry */
|
|
92
|
+
export function parseMeasurementText(text, source) {
|
|
93
|
+
let parsed;
|
|
94
|
+
try {
|
|
95
|
+
parsed = JSON.parse(text);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new MeasurementError([`invalid JSON (${error.message})`], source);
|
|
99
|
+
}
|
|
100
|
+
const leaks = findLeaks(text).map((name) => `contains ${name}`);
|
|
101
|
+
if (leaks.length > 0)
|
|
102
|
+
throw new MeasurementError(leaks, source);
|
|
103
|
+
return parseMeasurement(parsed, source);
|
|
104
|
+
}
|
|
105
|
+
/** where a run is stored, relative to `measurements/`: `<rig>/<date>[-<experiment>].json` */
|
|
106
|
+
export function measurementPath(measurement, experiment) {
|
|
107
|
+
return `${measurement.rig}/${measurement.date}${experiment ? `-${experiment}` : ''}.json`;
|
|
108
|
+
}
|
|
109
|
+
/** whether a path under `measurements/` matches the rig and date inside the file */
|
|
110
|
+
export function pathMatches(path, measurement) {
|
|
111
|
+
const expected = `${measurement.rig}/${measurement.date}`;
|
|
112
|
+
return (path === `${expected}.json` || (path.startsWith(`${expected}-`) && path.endsWith('.json')));
|
|
113
|
+
}
|
|
114
|
+
/** the file text a rig writes: tab indented, one trailing newline, `schema` first */
|
|
115
|
+
export function serialiseMeasurement(measurement) {
|
|
116
|
+
return `${JSON.stringify({ schema: MEASUREMENT_SCHEMA, ...measurement }, null, '\t')}\n`;
|
|
117
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** SWD v4 network + data centre + device, in kWh/GB */
|
|
2
|
+
export declare function swdTotal(): number;
|
|
3
|
+
/** attributional joules for moving `bytes`, at `kwhPerGb` */
|
|
4
|
+
export declare function attributionalJoules(bytes: number, kwhPerGb?: number): number;
|
|
5
|
+
/** what one zero-network local view avoids, before a rig replaces the modelled terms */
|
|
6
|
+
export type ViewTerms = {
|
|
7
|
+
bytes: number;
|
|
8
|
+
originJ: number;
|
|
9
|
+
radioJ: number;
|
|
10
|
+
mobileShare: number;
|
|
11
|
+
};
|
|
12
|
+
/** the modelled defaults: the replaced document, a conventional origin, the attributed radio wake */
|
|
13
|
+
export declare const MODELLED_VIEW: ViewTerms;
|
|
14
|
+
/** joules avoided per local view: attributional bytes + origin request + radio wake on phones */
|
|
15
|
+
export declare function joulesPerView(terms?: ViewTerms): number;
|
|
16
|
+
/**
|
|
17
|
+
* Joules avoided per local view where the origin's own energy for that workload was measured. The
|
|
18
|
+
* measured joules replace SWD's data-centre term and the modelled origin request, so the figure
|
|
19
|
+
* keeps the network and device terms of the bytes, the measured origin joules and the radio wake.
|
|
20
|
+
*/
|
|
21
|
+
export declare function joulesPerViewWithOrigin(originJ: number, terms?: Pick<ViewTerms, 'bytes' | 'radioJ' | 'mobileShare'>): number;
|
|
22
|
+
/** the data-centre term of the bytes in a view, the part measured origin joules replace */
|
|
23
|
+
export declare function dataCentreJoules(bytes?: number): number;
|
|
24
|
+
/** the views channel: annual views x local share x joules per local view, in MWh */
|
|
25
|
+
export declare function viewsChannelMWh(annualViews: number, localShare: number, jPerView?: number): number;
|
|
26
|
+
/** a year of one server's facility draw, in MWh */
|
|
27
|
+
export declare function serverYearMWh(watts?: number, pue?: number): number;
|
|
28
|
+
/** origin work removed at peak: local share x the share of load that is reads */
|
|
29
|
+
export declare function peakCut(localShare: number, readShare?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Servers still needed after spool removes `cut` of the peak work.
|
|
32
|
+
*
|
|
33
|
+
* A sensitivity model only: a real institution is sized from its peak traces and SLOs, which this
|
|
34
|
+
* proportional rule does not see.
|
|
35
|
+
*/
|
|
36
|
+
export declare function serversAfter(before: number, cut: number, floor?: number): number;
|
|
37
|
+
/** MWh a year from the servers the cut frees, if they are actually removed */
|
|
38
|
+
export declare function capacityMWh(before: number, cut: number, floor?: number, perServer?: number): number;
|
|
39
|
+
/** the smallest throughput-sized fleet whose freed servers plus the views channel reach `target` */
|
|
40
|
+
export declare function fleetFor(targetMWh: number, viewsMWh: number, cut: number, floor?: number, perServer?: number): number;
|
|
41
|
+
/** monthly views under the free request allowance when `localShare` of views make no request */
|
|
42
|
+
export declare function freeTierCeiling(localShare: number, localViewsPerSync?: number, base?: number): number;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DOCUMENT_BYTES, FREE_TIER_VIEWS, MOBILE_SHARE, ORIGIN_J, PUE, RADIO_J, READ_SHARE, SERVER_FLOOR, SERVER_WATTS, SWD_V4 } from './inputs.js';
|
|
2
|
+
const J_PER_KWH = 3.6e6;
|
|
3
|
+
const J_PER_MWH = 3.6e9;
|
|
4
|
+
const HOURS_PER_YEAR = 8760;
|
|
5
|
+
/** SWD v4 network + data centre + device, in kWh/GB */
|
|
6
|
+
export function swdTotal() {
|
|
7
|
+
return SWD_V4.network.value + SWD_V4.datacentre.value + SWD_V4.device.value;
|
|
8
|
+
}
|
|
9
|
+
/** attributional joules for moving `bytes`, at `kwhPerGb` */
|
|
10
|
+
export function attributionalJoules(bytes, kwhPerGb = swdTotal()) {
|
|
11
|
+
return (bytes / 1e9) * kwhPerGb * J_PER_KWH;
|
|
12
|
+
}
|
|
13
|
+
/** the modelled defaults: the replaced document, a conventional origin, the attributed radio wake */
|
|
14
|
+
export const MODELLED_VIEW = {
|
|
15
|
+
bytes: DOCUMENT_BYTES.value,
|
|
16
|
+
originJ: ORIGIN_J.conventional.value,
|
|
17
|
+
radioJ: RADIO_J.attributed.value,
|
|
18
|
+
mobileShare: MOBILE_SHARE.value
|
|
19
|
+
};
|
|
20
|
+
/** joules avoided per local view: attributional bytes + origin request + radio wake on phones */
|
|
21
|
+
export function joulesPerView(terms = MODELLED_VIEW) {
|
|
22
|
+
return attributionalJoules(terms.bytes) + terms.originJ + terms.mobileShare * terms.radioJ;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Joules avoided per local view where the origin's own energy for that workload was measured. The
|
|
26
|
+
* measured joules replace SWD's data-centre term and the modelled origin request, so the figure
|
|
27
|
+
* keeps the network and device terms of the bytes, the measured origin joules and the radio wake.
|
|
28
|
+
*/
|
|
29
|
+
export function joulesPerViewWithOrigin(originJ, terms = MODELLED_VIEW) {
|
|
30
|
+
const outside = SWD_V4.network.value + SWD_V4.device.value;
|
|
31
|
+
return attributionalJoules(terms.bytes, outside) + originJ + terms.mobileShare * terms.radioJ;
|
|
32
|
+
}
|
|
33
|
+
/** the data-centre term of the bytes in a view, the part measured origin joules replace */
|
|
34
|
+
export function dataCentreJoules(bytes = DOCUMENT_BYTES.value) {
|
|
35
|
+
return attributionalJoules(bytes, SWD_V4.datacentre.value);
|
|
36
|
+
}
|
|
37
|
+
/** the views channel: annual views x local share x joules per local view, in MWh */
|
|
38
|
+
export function viewsChannelMWh(annualViews, localShare, jPerView = joulesPerView()) {
|
|
39
|
+
return (annualViews * localShare * jPerView) / J_PER_MWH;
|
|
40
|
+
}
|
|
41
|
+
/** a year of one server's facility draw, in MWh */
|
|
42
|
+
export function serverYearMWh(watts = SERVER_WATTS.value, pue = PUE.value) {
|
|
43
|
+
return (watts * pue * HOURS_PER_YEAR) / 1e6;
|
|
44
|
+
}
|
|
45
|
+
/** origin work removed at peak: local share x the share of load that is reads */
|
|
46
|
+
export function peakCut(localShare, readShare = READ_SHARE.value) {
|
|
47
|
+
return localShare * readShare;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Servers still needed after spool removes `cut` of the peak work.
|
|
51
|
+
*
|
|
52
|
+
* A sensitivity model only: a real institution is sized from its peak traces and SLOs, which this
|
|
53
|
+
* proportional rule does not see.
|
|
54
|
+
*/
|
|
55
|
+
export function serversAfter(before, cut, floor = SERVER_FLOOR.value) {
|
|
56
|
+
return Math.max(floor, Math.ceil(before * (1 - cut)));
|
|
57
|
+
}
|
|
58
|
+
/** MWh a year from the servers the cut frees, if they are actually removed */
|
|
59
|
+
export function capacityMWh(before, cut, floor = SERVER_FLOOR.value, perServer = serverYearMWh()) {
|
|
60
|
+
return (before - serversAfter(before, cut, floor)) * perServer;
|
|
61
|
+
}
|
|
62
|
+
/** the smallest throughput-sized fleet whose freed servers plus the views channel reach `target` */
|
|
63
|
+
export function fleetFor(targetMWh, viewsMWh, cut, floor = SERVER_FLOOR.value, perServer = serverYearMWh()) {
|
|
64
|
+
if (cut <= 0)
|
|
65
|
+
throw new RangeError('a cut of zero frees no server');
|
|
66
|
+
let n = floor;
|
|
67
|
+
while (capacityMWh(n, cut, floor, perServer) + viewsMWh < targetMWh)
|
|
68
|
+
n++;
|
|
69
|
+
return n;
|
|
70
|
+
}
|
|
71
|
+
/** monthly views under the free request allowance when `localShare` of views make no request */
|
|
72
|
+
export function freeTierCeiling(localShare, localViewsPerSync = 20, base = FREE_TIER_VIEWS.value) {
|
|
73
|
+
return base / (1 - localShare + localShare / localViewsPerSync);
|
|
74
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { TimedView } from '../protocol/view.js';
|
|
2
|
+
/** what a third-party origin is for, as far as the table below knows */
|
|
3
|
+
export type OriginClass = 'analytics' | 'ads' | 'consent' | 'fonts' | 'cdn' | 'video' | 'maps' | 'social' | 'chat' | 'unknown';
|
|
4
|
+
/**
|
|
5
|
+
* What can be done about a class, from the third-party surveys of 2026-10-19:
|
|
6
|
+
* `defer` holds the request and sends it later, `cache` keeps a versioned file, `self-host` removes
|
|
7
|
+
* the request, `network` stays on the network, `review` means the origin is not in the table.
|
|
8
|
+
*/
|
|
9
|
+
export type Remedy = 'defer' | 'cache' | 'self-host' | 'network' | 'review';
|
|
10
|
+
/** a known origin suffix, its class and what can be done */
|
|
11
|
+
export type KnownOrigin = {
|
|
12
|
+
suffix: string;
|
|
13
|
+
class: OriginClass;
|
|
14
|
+
remedy: Remedy;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A short table of common third-party hosts. It is a starting point for a site to extend, not a
|
|
18
|
+
* claim about any vendor's behaviour: the class and remedy come from reading vendor documentation
|
|
19
|
+
* in the surveys and are not measured here.
|
|
20
|
+
*/
|
|
21
|
+
export declare const KNOWN_ORIGINS: readonly KnownOrigin[];
|
|
22
|
+
/** the class and remedy of an origin: the longest table suffix its host ends with, else unknown */
|
|
23
|
+
export declare function classifyOrigin(origin: string, table?: readonly KnownOrigin[]): {
|
|
24
|
+
class: OriginClass;
|
|
25
|
+
remedy: Remedy;
|
|
26
|
+
};
|
|
27
|
+
/** one third-party origin and what it costs the site's zero-network views */
|
|
28
|
+
export type ThirdPartyRow = {
|
|
29
|
+
origin: string;
|
|
30
|
+
class: OriginClass;
|
|
31
|
+
remedy: Remedy;
|
|
32
|
+
/** reported views that loaded anything from this origin */
|
|
33
|
+
views: number;
|
|
34
|
+
/** resources loaded from it, summed over those views */
|
|
35
|
+
loads: number;
|
|
36
|
+
/** `views` as a share of reported views */
|
|
37
|
+
share: number;
|
|
38
|
+
/** views whose only third-party origin was this one: the ones removing it would unblock */
|
|
39
|
+
soloViews: number;
|
|
40
|
+
};
|
|
41
|
+
/** the per-site third-party report */
|
|
42
|
+
export type ThirdPartyReport = {
|
|
43
|
+
/** every view in the stream */
|
|
44
|
+
views: number;
|
|
45
|
+
/** views whose page reported a cross-origin count; the rest are unknown, never counted as clean */
|
|
46
|
+
reported: number;
|
|
47
|
+
/** reported views with no cross-origin load: strict zero-network candidates */
|
|
48
|
+
clean: number;
|
|
49
|
+
/** reported views with at least one */
|
|
50
|
+
blocked: number;
|
|
51
|
+
/** blocked views whose report named no origin, such as one from an older page runtime */
|
|
52
|
+
unnamed: number;
|
|
53
|
+
/** origins by `soloViews`, then `views`, then name */
|
|
54
|
+
rows: ThirdPartyRow[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* What blocks zero-network on this site: for each third-party origin the views that loaded from it,
|
|
58
|
+
* ranked by how many views it alone blocks. Pass the views from `viewsOf`, which joins each page's
|
|
59
|
+
* loads report to its view. The counts are an upper bound on network requests, since a cross-origin
|
|
60
|
+
* resource timing entry says nothing about cache hits without `Timing-Allow-Origin`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function thirdPartyReport(views: readonly TimedView[], table?: readonly KnownOrigin[]): ThirdPartyReport;
|