Skip to content
Merged
24 changes: 23 additions & 1 deletion apps/landing/src/app/benchmark-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,27 @@ import fixture from '../../../../e2e/fixtures/benchmark-results.json'
export const BENCHMARK_SOURCE =
process.env.LANDING_BENCHMARK_DATA === 'fixture' ? 'fixture' : 'live'

export const benchmarkResults: typeof live =
// The fields the page reads. The refresh rewrites the live file in its
// current format while the fixture keeps the format it was frozen in, so the
// page must not depend on any field it does not read.
export interface BenchmarkResults {
run: {
id: string
url: string
commit: string
next: string
devupUi: string
sha: string
}
samples: number
rows: {
table: string
target: string
version: string
median: number
bytes: number
}[]
}

export const benchmarkResults: BenchmarkResults =
BENCHMARK_SOURCE === 'fixture' ? fixture : live
35 changes: 29 additions & 6 deletions benchmark-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,40 @@ export function trend(history, target, control) {
.join('\n')
}

/** JSON as Prettier prints it here: two spaces, short arrays of numbers or strings on one line */
/**
* A long array of numbers as Prettier fills it: as many items on each line as
* fit, every line but the last ending in a comma
*/
function fillNumbers(indent, key, values) {
const inner = `${indent} `
const lines = []
let line = inner
for (const [index, value] of values.entries()) {
const item = index < values.length - 1 ? `${value},` : value
const next = line === inner ? `${inner}${item}` : `${line} ${item}`
if (line !== inner && next.length > PRINT_WIDTH) {
lines.push(line)
line = `${inner}${item}`
} else line = next
}
return `${indent}${key}[\n${[...lines, line].join('\n')}\n${indent}]`
}

/**
* JSON as Prettier prints it here: two spaces, short arrays of numbers or
* strings on one line, and longer arrays of numbers filled over lines
*/
export function formatJson(value) {
return (
JSON.stringify(value, null, 2).replace(
/^( *)(.*)\[\n((?:\1 {2}(?:-?[\d.e+-]+|"[^"\n]*"|null),?\n)+)\1\]/gm,
(whole, indent, key, items) => {
const line = `${indent}${key}[${items
.trim()
.split(/,\n */)
.join(', ')}]`
return line.length + 1 <= PRINT_WIDTH ? line : whole
const values = items.trim().split(/,\n */)
const line = `${indent}${key}[${values.join(', ')}]`
if (line.length + 1 <= PRINT_WIDTH) return line
return values.every((item) => /^-?[\d.e+-]+$/.test(item))
? fillNumbers(indent, key, values)
: whole
},
) + '\n'
)
Expand Down
49 changes: 7 additions & 42 deletions benchmark/history.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@
"devup-ui-single-turbo": [3.85, 3.815, 3.852, 28914697, 325, 571234],
"devup-ui-turbo": [3.885, 3.881, 3.886, 28940461, 356, 571297],
"vanilla-extract-devup-ui": [
3.819,
3.792,
3.864,
28964098,
376,
571331
3.819, 3.792, 3.864, 28964098, 376, 571331
],
"tailwind-turbo-devup-ui": [3.803, 3.798, 3.806, 28926709, 381, 571325],
"vinext-devup-ui": [1.895, 1.848, 1.997, 1290682, 10529, 486447],
Expand All @@ -74,12 +69,7 @@
"devup-ui-large-wasm": [13.951, 13.575, 14.281, 88999119, 1592, 934533],
"devup-ui-large-turbo": [5.407, 5.255, 5.555, 38645324, 1512, 571629],
"devup-ui-large-turbo-wasm": [
5.847,
5.742,
5.959,
38663728,
1512,
571629
5.847, 5.742, 5.959, 38663728, 1512, 571629
]
}
},
Expand Down Expand Up @@ -115,12 +105,7 @@
"devup-ui-large-wasm": [16.822, 16.767, 17.14, 89000733, 1592, 934533],
"devup-ui-large-turbo": [6.343, 6.291, 6.485, 38651995, 1512, 571629],
"devup-ui-large-turbo-wasm": [
6.927,
6.85,
7.186,
38676657,
1512,
571629
6.927, 6.85, 7.186, 38676657, 1512, 571629
]
}
},
Expand Down Expand Up @@ -149,12 +134,7 @@
"devup-ui-single-turbo": [5.136, 5.007, 5.305, 28901694, 325, 571234],
"devup-ui-turbo": [5.17, 5.123, 5.288, 28950247, 356, 571297],
"vanilla-extract-devup-ui": [
5.005,
4.986,
5.215,
28964779,
376,
571331
5.005, 4.986, 5.215, 28964779, 376, 571331
],
"tailwind-turbo-devup-ui": [5.185, 5.149, 5.366, 28928475, 381, 571325],
"vinext-devup-ui": [2.858, 2.837, 2.983, 1290682, 10529, 486447],
Expand All @@ -163,12 +143,7 @@
"devup-ui-large-wasm": [20.538, 20.511, 20.603, 88999216, 1592, 934533],
"devup-ui-large-turbo": [7.253, 7.236, 7.379, 38661348, 1512, 571629],
"devup-ui-large-turbo-wasm": [
7.792,
7.697,
7.802,
38686094,
1512,
571629
7.792, 7.697, 7.802, 38686094, 1512, 571629
]
}
},
Expand Down Expand Up @@ -197,12 +172,7 @@
"devup-ui-single-turbo": [4.67, 4.638, 4.694, 28916568, 325, 571234],
"devup-ui-turbo": [4.777, 4.683, 4.87, 28956268, 356, 571297],
"vanilla-extract-devup-ui": [
4.597,
4.506,
4.627,
28953896,
376,
571331
4.597, 4.506, 4.627, 28953896, 376, 571331
],
"tailwind-turbo-devup-ui": [4.603, 4.594, 4.833, 28925356, 381, 571325],
"vinext-devup-ui": [2.467, 2.316, 2.521, 1287690, 9033, 484951],
Expand All @@ -211,12 +181,7 @@
"devup-ui-large-wasm": [16.845, 16.789, 17.405, 88997162, 1388, 934329],
"devup-ui-large-turbo": [6.429, 6.26, 6.601, 38651438, 1512, 571629],
"devup-ui-large-turbo-wasm": [
6.888,
6.729,
7.032,
38662944,
1512,
571629
6.888, 6.729, 7.032, 38662944, 1512, 571629
]
}
}
Expand Down
25 changes: 20 additions & 5 deletions packages/plugin-utils/src/__tests__/benchmark-record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,35 @@ describe('benchmark refresh order', () => {
})

describe('benchmark JSON', () => {
it('prints short arrays on one line and long ones one item per line', () => {
it('prints short arrays on one line, fills long numbers and splits long strings', () => {
const long = Array.from({ length: 12 }, (_, index) => 1_000_000 + index)
const longNames = Array.from(
{ length: 6 },
(_, index) => `target-${index}-xxxxxxxx`,
)

// As Prettier prints them, so `bun run lint` accepts what the refresh writes
expect(
formatJson({ short: [1, 2.5, null], names: ['a', 'b'], long, empty: [] }),
formatJson({
short: [1, 2.5, null],
names: ['a', 'b'],
long,
longNames,
empty: [],
}),
).toBe(
[
'{',
' "short": [1, 2.5, null],',
' "names": ["a", "b"],',
' "long": [',
...long.map(
(value, index) =>
` ${value}${index === long.length - 1 ? '' : ','}`,
' 1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006, 1000007,',
' 1000008, 1000009, 1000010, 1000011',
' ],',
' "longNames": [',
...longNames.map(
(name, index) =>
` "${name}"${index === longNames.length - 1 ? '' : ','}`,
),
' ],',
' "empty": []',
Expand Down
Loading