-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.mjs
More file actions
216 lines (205 loc) · 8.1 KB
/
Copy pathmatrix.mjs
File metadata and controls
216 lines (205 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Defines which matrix cells run for each app.
//
// A cell is { pool, env, isolate, fsCache, state, workers? }:
// pool forks | threads | vmThreads | vmForks | browser
// (browser = headless Chromium via playwright; node-pool
// dimensions don't apply to it)
// env node | jsdom | happy-dom | chromium
// isolate boolean
// fsCache boolean (fs module cache)
// state cold (all persistent caches wiped before every rep)
// | warm (one untimed priming run, caches kept between reps)
// workers optional maxWorkers value ('50%', '100%', ...)
// coverage none | v8 | istanbul (only set by the coverage matrix)
//
// `best` is the fastest warm node-pool row of the app in the README tables;
// the coverage bench (scripts/bench-coverage.mjs) measures coverage on it.
//
// Levels:
// quick — one representative cell per app (CI smoke: does the suite pass)
// default — curated cells covering the dimensions the app was built to
// measure; skips combinations that add runtime but no signal
// full — full cross product of everything the app supports (use with
// --apps, the complete run is large)
const POOLS = ['forks', 'threads', 'vmThreads', 'vmForks']
const t = true
const f = false
const APPS = {
'micro-utils': {
best: { pool: 'threads', env: 'node', isolate: f, fsCache: f, state: 'warm' },
envs: ['node', 'jsdom', 'happy-dom'],
primary: 'node',
dims: { pool: POOLS, env: ['node'], isolate: [t, f], fsCache: [f], state: ['cold', 'warm'] },
// the most common real-world waste: a tiny node-only suite running under
// an inherited DOM environment
extra: [
{ pool: 'forks', env: 'jsdom', isolate: t, fsCache: f, state: 'warm' },
{ pool: 'forks', env: 'happy-dom', isolate: t, fsCache: f, state: 'warm' },
],
},
'node-library': {
best: { pool: 'threads', env: 'node', isolate: f, fsCache: t, state: 'warm' },
envs: ['node', 'jsdom', 'happy-dom'],
primary: 'node',
dims: { pool: ['forks', 'threads'], env: ['node'], isolate: [t, f], fsCache: [f, t], state: ['cold', 'warm'] },
extra: [
{ pool: 'forks', env: 'jsdom', isolate: t, fsCache: f, state: 'warm' },
],
},
'node-backend': {
best: { pool: 'threads', env: 'node', isolate: f, fsCache: f, state: 'warm' },
envs: ['node'],
primary: 'node',
dims: { pool: POOLS, env: ['node'], isolate: [t, f], fsCache: [f], state: ['warm'] },
extra: [
{ pool: 'forks', env: 'node', isolate: t, fsCache: f, state: 'cold' },
],
},
'deps-heavy': {
best: { pool: 'vmThreads', env: 'node', isolate: f, fsCache: f, state: 'warm' },
envs: ['node'],
primary: 'node',
dims: { pool: POOLS, env: ['node'], isolate: [t, f], fsCache: [f], state: ['warm'] },
extra: [
{ pool: 'forks', env: 'node', isolate: t, fsCache: f, state: 'cold' },
{ pool: 'vmThreads', env: 'node', isolate: t, fsCache: f, state: 'cold' },
],
},
'react-spa': {
best: { pool: 'threads', env: 'happy-dom', isolate: f, fsCache: f, state: 'warm' },
envs: ['jsdom', 'happy-dom'],
primary: 'jsdom',
browser: true,
dims: { pool: ['forks', 'threads', 'vmThreads'], env: ['jsdom', 'happy-dom'], isolate: [t, f], fsCache: [f], state: ['warm'] },
extra: [
{ pool: 'forks', env: 'jsdom', isolate: t, fsCache: f, state: 'cold' },
{ pool: 'forks', env: 'jsdom', isolate: t, fsCache: t, state: 'cold' },
{ pool: 'forks', env: 'jsdom', isolate: t, fsCache: t, state: 'warm' },
],
},
'vue-spa': {
best: { pool: 'threads', env: 'happy-dom', isolate: f, fsCache: f, state: 'warm' },
envs: ['jsdom', 'happy-dom'],
primary: 'jsdom',
browser: true,
dims: { pool: ['forks', 'threads'], env: ['jsdom', 'happy-dom'], isolate: [t, f], fsCache: [f], state: ['warm'] },
extra: [
{ pool: 'forks', env: 'jsdom', isolate: t, fsCache: f, state: 'cold' },
],
},
'design-system': {
best: { pool: 'forks', env: 'happy-dom', isolate: f, fsCache: f, state: 'warm' },
envs: ['jsdom', 'happy-dom'],
primary: 'jsdom',
browser: true,
dims: { pool: ['forks', 'vmThreads'], env: ['jsdom', 'happy-dom'], isolate: [t, f], fsCache: [f], state: ['warm'] },
extra: [
{ pool: 'forks', env: 'jsdom', isolate: t, fsCache: f, state: 'cold' },
],
},
'barrel-hell': {
best: { pool: 'threads', env: 'node', isolate: f, fsCache: t, state: 'warm' },
envs: ['node'],
primary: 'node',
dims: { pool: ['forks', 'threads'], env: ['node'], isolate: [t, f], fsCache: [f, t], state: ['cold', 'warm'] },
},
'enterprise-monolith': {
best: { pool: 'threads', env: 'node', isolate: f, fsCache: t, state: 'warm' },
envs: ['node'],
primary: 'node',
dims: { pool: ['forks', 'threads'], env: ['node'], isolate: [t, f], fsCache: [f, t], state: ['cold', 'warm'] },
extra: [
{ pool: 'forks', env: 'node', isolate: f, fsCache: f, state: 'warm', workers: '50%' },
],
},
'long-haul': {
best: { pool: 'vmForks', env: 'happy-dom', isolate: t, fsCache: f, state: 'warm', workers: '2' },
envs: ['jsdom', 'happy-dom'],
primary: 'jsdom',
workers: ['2'],
// 2 workers x 40 heavy files each: long enough worker lifetimes for
// retention, memory-limit recycling and aging to show up in wall time
dims: { pool: POOLS, env: ['jsdom'], isolate: [t], fsCache: [f], state: ['warm'], workers: ['2'] },
extra: [
{ pool: 'vmForks', env: 'jsdom', isolate: t, fsCache: f, state: 'cold', workers: '2' },
{ pool: 'forks', env: 'happy-dom', isolate: t, fsCache: f, state: 'warm', workers: '2' },
{ pool: 'vmForks', env: 'happy-dom', isolate: t, fsCache: f, state: 'warm', workers: '2' },
],
},
'cpu-bound': {
best: { pool: 'forks', env: 'node', isolate: f, fsCache: f, state: 'warm', workers: '100%' },
envs: ['node'],
primary: 'node',
workers: ['25%', '50%', '100%'],
dims: { pool: ['forks', 'threads'], env: ['node'], isolate: [t], fsCache: [f], state: ['warm'], workers: ['25%', '50%', '100%'] },
extra: [
{ pool: 'forks', env: 'node', isolate: f, fsCache: f, state: 'warm', workers: '100%' },
],
},
}
export const APP_NAMES = Object.keys(APPS)
function cross(dims) {
const cells = [{}]
const result = Object.entries(dims).reduce((acc, [key, values]) => {
const next = []
for (const cell of acc) {
for (const value of values)
next.push({ ...cell, [key]: value })
}
return next
}, cells)
return result
}
function browserCells(spec, states) {
if (!spec.browser)
return []
return states.map(state => ({ pool: 'browser', env: 'chromium', isolate: true, fsCache: false, state }))
}
export function cellsFor(app, level) {
const spec = APPS[app]
if (!spec)
throw new Error(`no matrix defined for app "${app}"`)
if (level === 'quick') {
return [
{ pool: 'forks', env: spec.primary, isolate: true, fsCache: false, state: 'warm' },
...browserCells(spec, ['warm']),
]
}
if (level === 'full') {
return [
...cross({
pool: POOLS,
env: spec.envs,
isolate: [true, false],
fsCache: [false, true],
state: ['cold', 'warm'],
...(spec.workers ? { workers: spec.workers } : {}),
}),
...browserCells(spec, ['cold', 'warm']),
]
}
return [...cross(spec.dims), ...(spec.extra ?? []), ...browserCells(spec, ['cold', 'warm'])]
}
// The coverage matrix: the app's fastest row without coverage (the baseline
// for the overhead), then the same row with each coverage provider.
export const COVERAGE_PROVIDERS = ['none', 'v8', 'istanbul']
export function bestFor(app) {
return APPS[app]?.best ?? null
}
export function coverageCellsFor(app) {
const spec = APPS[app]
if (!spec?.best)
throw new Error(`no best row defined for app "${app}"`)
return COVERAGE_PROVIDERS.map(coverage => ({ ...spec.best, coverage }))
}
export function cellKey(cell) {
return [
cell.pool,
cell.env,
`isolate:${cell.isolate}`,
`fsCache:${cell.fsCache}`,
cell.workers ? `workers:${cell.workers}` : 'workers:default',
cell.state,
...(cell.coverage ? [`coverage:${cell.coverage}`] : []),
].join(' ')
}