mirror of https://github.com/sveltejs/svelte
commit
0ae5d7a8fb
@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
'svelte': patch
|
|
||||||
---
|
|
||||||
|
|
||||||
chore: drop dead code that make TSGO fail
|
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: cancel deferred event listeners during cleanup
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
perf: speed up parser interactions with Acorn or avoid them where possible
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: serialize input default values during server rendering
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: remove `WAS_MARKED` flag in favor of `Set`
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: throw `set_context_after_init` when `setContext` is called after an `await` during SSR
|
||||||
@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
'svelte': patch
|
|
||||||
---
|
|
||||||
|
|
||||||
fix: correctly transform declaration tags during SSR
|
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
perf: avoid regex matching in parser where possible
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: in non-async mode, only push variable to current_sources when active_reaction is updating
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: recognise `aria-braillelabel` and `aria-brailleroledescription` as known ARIA attributes
|
||||||
@ -1,229 +0,0 @@
|
|||||||
name: pkg.pr.new
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types: [opened, synchronize]
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
sha:
|
|
||||||
description: 'Commit SHA to build'
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
pr:
|
|
||||||
description: 'PR number to comment on'
|
|
||||||
required: true
|
|
||||||
type: number
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
# Skip pull_request_target events from forks — maintainers can use workflow_dispatch instead
|
|
||||||
if: >
|
|
||||||
github.event_name != 'pull_request_target' ||
|
|
||||||
github.event.pull_request.head.repo.full_name == github.repository
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
# No permissions — this job runs user-controlled code
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
with:
|
|
||||||
# For pull_request_target, check out the PR head.
|
|
||||||
# For workflow_dispatch, check out the manually specified SHA.
|
|
||||||
# For push, fall back to the push SHA.
|
|
||||||
ref: ${{ github.event.pull_request.head.sha || inputs.sha || github.sha }}
|
|
||||||
|
|
||||||
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4
|
|
||||||
- uses: actions/setup-node@v6
|
|
||||||
with:
|
|
||||||
node-version: 22.x
|
|
||||||
cache: pnpm
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: pnpm build
|
|
||||||
|
|
||||||
- run: pnpx pkg-pr-new publish --comment=off --json output.json --compact --no-template './packages/svelte'
|
|
||||||
|
|
||||||
- name: Upload output
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: output
|
|
||||||
path: ./output.json
|
|
||||||
|
|
||||||
# Sanitizes the untrusted output from the build job before it's consumed by
|
|
||||||
# jobs with elevated permissions. This ensures that only known package names
|
|
||||||
# and valid SHA prefixes make it through.
|
|
||||||
sanitize:
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download artifact
|
|
||||||
uses: actions/download-artifact@v7
|
|
||||||
with:
|
|
||||||
name: output
|
|
||||||
|
|
||||||
- name: Sanitize output
|
|
||||||
uses: actions/github-script@v8
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const fs = require('fs');
|
|
||||||
const raw = JSON.parse(fs.readFileSync('output.json', 'utf8'));
|
|
||||||
|
|
||||||
const ALLOWED_PACKAGES = new Set(['svelte']);
|
|
||||||
const SHA_PATTERN = /^[0-9a-f]{7}$/;
|
|
||||||
|
|
||||||
const packages = (raw.packages || [])
|
|
||||||
.filter(p => {
|
|
||||||
if (!ALLOWED_PACKAGES.has(p.name)) {
|
|
||||||
console.log(`Skipping unexpected package: ${JSON.stringify(p.name)}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const sha = p.url?.replace(/^.+@([^@]+)$/, '$1');
|
|
||||||
if (!sha || !SHA_PATTERN.test(sha)) {
|
|
||||||
console.log(`Skipping package with invalid SHA: ${JSON.stringify(p.url)}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.map(p => ({
|
|
||||||
name: p.name,
|
|
||||||
sha: p.url.replace(/^.+@([^@]+)$/, '$1'),
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.writeFileSync('sanitized-output.json', JSON.stringify({ packages }), 'utf8');
|
|
||||||
|
|
||||||
- name: Upload sanitized output
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sanitized-output
|
|
||||||
path: ./sanitized-output.json
|
|
||||||
|
|
||||||
comment:
|
|
||||||
needs: sanitize
|
|
||||||
if: github.event_name == 'pull_request_target' || github.event_name == 'workflow_dispatch'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download sanitized artifact
|
|
||||||
uses: actions/download-artifact@v7
|
|
||||||
with:
|
|
||||||
name: sanitized-output
|
|
||||||
|
|
||||||
- name: Resolve PR number
|
|
||||||
id: pr
|
|
||||||
uses: actions/github-script@v8
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
if (context.eventName === 'pull_request_target') {
|
|
||||||
core.setOutput('number', context.issue.number);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For workflow_dispatch, use the explicitly provided PR number.
|
|
||||||
// We can't use listPullRequestsAssociatedWithCommit because fork
|
|
||||||
// commits don't exist in the base repo, so the API returns nothing.
|
|
||||||
const pr = Number('${{ inputs.pr }}');
|
|
||||||
if (!pr || isNaN(pr)) {
|
|
||||||
core.setFailed('workflow_dispatch requires a valid pr input');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.setOutput('number', pr);
|
|
||||||
|
|
||||||
- name: Post or update comment
|
|
||||||
uses: actions/github-script@v8
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
script: |
|
|
||||||
const fs = require('fs');
|
|
||||||
const { packages } = JSON.parse(fs.readFileSync('sanitized-output.json', 'utf8'));
|
|
||||||
|
|
||||||
if (packages.length === 0) {
|
|
||||||
console.log('No valid packages found. Skipping comment.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const issue_number = parseInt('${{ steps.pr.outputs.number }}', 10);
|
|
||||||
|
|
||||||
const bot_comment_identifier = `<!-- pkg.pr.new comment -->`;
|
|
||||||
|
|
||||||
const body = `${bot_comment_identifier}
|
|
||||||
|
|
||||||
[Playground](https://svelte.dev/playground?version=pr-${issue_number})
|
|
||||||
|
|
||||||
\`\`\`
|
|
||||||
${packages.map(p => `pnpm add https://pkg.pr.new/${p.name}@${issue_number}`).join('\n')}
|
|
||||||
\`\`\`
|
|
||||||
`;
|
|
||||||
|
|
||||||
const comments = await github.rest.issues.listComments({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number,
|
|
||||||
});
|
|
||||||
const existing = comments.data.find(c => c.body.includes(bot_comment_identifier));
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
await github.rest.issues.updateComment({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
comment_id: existing.id,
|
|
||||||
body,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await github.rest.issues.createComment({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number,
|
|
||||||
body,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
log:
|
|
||||||
needs: sanitize
|
|
||||||
if: github.event_name == 'push'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download sanitized artifact
|
|
||||||
uses: actions/download-artifact@v7
|
|
||||||
with:
|
|
||||||
name: sanitized-output
|
|
||||||
|
|
||||||
- name: Log publish info
|
|
||||||
uses: actions/github-script@v8
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const fs = require('fs');
|
|
||||||
const { packages } = JSON.parse(fs.readFileSync('sanitized-output.json', 'utf8'));
|
|
||||||
|
|
||||||
if (packages.length === 0) {
|
|
||||||
console.log('No valid packages found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\n' + '='.repeat(50));
|
|
||||||
console.log('Publish Information');
|
|
||||||
console.log('='.repeat(50));
|
|
||||||
for (const p of packages) {
|
|
||||||
console.log(`${p.name} - pnpm add https://pkg.pr.new/${p.name}@${p.sha}`);
|
|
||||||
}
|
|
||||||
const svelte = packages.find(p => p.name === 'svelte');
|
|
||||||
if (svelte) {
|
|
||||||
console.log(`\nPlayground: https://svelte.dev/playground?version=commit-${svelte.sha}`);
|
|
||||||
}
|
|
||||||
console.log('='.repeat(50));
|
|
||||||
@ -0,0 +1,346 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const root = path.resolve(fileURLToPath(import.meta.url), '../..');
|
||||||
|
const compiler_path = 'packages/svelte/src/compiler/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge V8 profiles from a Vitest run into a compiler-only flame graph and hotspot summary.
|
||||||
|
* Samples retain callees outside the compiler once execution has entered compiler code.
|
||||||
|
* @param {string} run_dir
|
||||||
|
*/
|
||||||
|
export function analyze_compiler_profiles(run_dir) {
|
||||||
|
const raw_dir = path.join(run_dir, 'raw');
|
||||||
|
const profile_files = fs
|
||||||
|
.readdirSync(raw_dir)
|
||||||
|
.filter((file) => file.endsWith('.cpuprofile'))
|
||||||
|
.sort();
|
||||||
|
|
||||||
|
if (profile_files.length === 0) {
|
||||||
|
throw new Error(`No CPU profiles found in ${raw_dir}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {Array<{ name: string, file?: string, line?: number, col?: number }>} */
|
||||||
|
const frames = [];
|
||||||
|
/** @type {Map<string, number>} */
|
||||||
|
const frame_indices = new Map();
|
||||||
|
/** @type {Map<string, { stack: number[], weight: number }>} */
|
||||||
|
const stacks = new Map();
|
||||||
|
/** @type {Map<string, Hotspot>} */
|
||||||
|
const hotspots = new Map();
|
||||||
|
/** @type {Map<string, Hotspot>} */
|
||||||
|
const files = new Map();
|
||||||
|
let total_time = 0;
|
||||||
|
let compiler_time = 0;
|
||||||
|
let garbage_collection_time = 0;
|
||||||
|
let total_samples = 0;
|
||||||
|
let compiler_samples = 0;
|
||||||
|
|
||||||
|
for (const profile_file of profile_files) {
|
||||||
|
let profile;
|
||||||
|
try {
|
||||||
|
profile = JSON.parse(fs.readFileSync(path.join(raw_dir, profile_file), 'utf8'));
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`Could not parse CPU profile ${profile_file}`, { cause: error });
|
||||||
|
}
|
||||||
|
const nodes = Array.isArray(profile.nodes) ? profile.nodes : [];
|
||||||
|
const samples = Array.isArray(profile.samples) ? profile.samples : [];
|
||||||
|
const time_deltas = Array.isArray(profile.timeDeltas) ? profile.timeDeltas : [];
|
||||||
|
const nodes_by_id = new Map(nodes.map((node) => [node.id, node]));
|
||||||
|
const parents = new Map();
|
||||||
|
|
||||||
|
for (const node of nodes) {
|
||||||
|
for (const child of node.children || []) {
|
||||||
|
parents.set(child, node.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < samples.length; i += 1) {
|
||||||
|
const weight = typeof time_deltas[i] === 'number' ? time_deltas[i] : 1;
|
||||||
|
const stack = get_stack(samples[i], nodes_by_id, parents);
|
||||||
|
total_time += weight;
|
||||||
|
total_samples += 1;
|
||||||
|
|
||||||
|
if (stack.at(-1)?.function_name === '(garbage collector)') {
|
||||||
|
garbage_collection_time += weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
const compiler_index = stack.findIndex((frame) => frame.url.includes(compiler_path));
|
||||||
|
if (compiler_index === -1) continue;
|
||||||
|
|
||||||
|
const compiler_stack = stack.slice(compiler_index);
|
||||||
|
const stack_indices = compiler_stack.map(get_frame_index);
|
||||||
|
const stack_key = stack_indices.join(',');
|
||||||
|
const existing_stack = stacks.get(stack_key);
|
||||||
|
|
||||||
|
if (existing_stack) {
|
||||||
|
existing_stack.weight += weight;
|
||||||
|
} else {
|
||||||
|
stacks.set(stack_key, { stack: stack_indices, weight });
|
||||||
|
}
|
||||||
|
|
||||||
|
compiler_time += weight;
|
||||||
|
compiler_samples += 1;
|
||||||
|
|
||||||
|
const leaf = compiler_stack.at(-1);
|
||||||
|
if (leaf) {
|
||||||
|
get_hotspot(hotspots, frame_key(leaf), leaf).self += weight;
|
||||||
|
get_hotspot(files, leaf.url || '(native)', {
|
||||||
|
...leaf,
|
||||||
|
function_name: leaf.url || '(native)'
|
||||||
|
}).self += weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
const seen_frames = new Set();
|
||||||
|
const seen_files = new Set();
|
||||||
|
|
||||||
|
for (const frame of compiler_stack) {
|
||||||
|
const key = frame_key(frame);
|
||||||
|
if (!seen_frames.has(key)) {
|
||||||
|
get_hotspot(hotspots, key, frame).inclusive += weight;
|
||||||
|
seen_frames.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = frame.url || '(native)';
|
||||||
|
if (!seen_files.has(file)) {
|
||||||
|
get_hotspot(files, file, { ...frame, function_name: file }).inclusive += weight;
|
||||||
|
seen_files.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compiler_time === 0) {
|
||||||
|
throw new Error('The CPU profiles contain no samples from packages/svelte/src/compiler');
|
||||||
|
}
|
||||||
|
|
||||||
|
const hotspot_rows = rank(hotspots, compiler_time);
|
||||||
|
const file_rows = rank(files, compiler_time);
|
||||||
|
const compact_stacks = [...stacks.values()];
|
||||||
|
const summary = {
|
||||||
|
profile_files: profile_files.length,
|
||||||
|
total_samples,
|
||||||
|
compiler_samples,
|
||||||
|
total_time_microseconds: total_time,
|
||||||
|
compiler_time_microseconds: compiler_time,
|
||||||
|
garbage_collection_time_microseconds: garbage_collection_time,
|
||||||
|
compiler_share_percent: (compiler_time * 100) / total_time,
|
||||||
|
hotspots: hotspot_rows,
|
||||||
|
files: file_rows
|
||||||
|
};
|
||||||
|
const speedscope = {
|
||||||
|
$schema: 'https://www.speedscope.app/file-format-schema.json',
|
||||||
|
name: `Svelte compiler: ${path.basename(run_dir)}`,
|
||||||
|
exporter: 'Svelte compiler test profiler',
|
||||||
|
activeProfileIndex: 0,
|
||||||
|
shared: { frames },
|
||||||
|
profiles: [
|
||||||
|
{
|
||||||
|
type: 'sampled',
|
||||||
|
name: 'Compiler-active samples from pnpm test',
|
||||||
|
unit: 'microseconds',
|
||||||
|
startValue: 0,
|
||||||
|
endValue: compiler_time,
|
||||||
|
samples: compact_stacks.map((entry) => entry.stack),
|
||||||
|
weights: compact_stacks.map((entry) => entry.weight)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(run_dir, 'flamegraph.speedscope.json'),
|
||||||
|
`${JSON.stringify(speedscope)}\n`
|
||||||
|
);
|
||||||
|
fs.writeFileSync(path.join(run_dir, 'summary.json'), `${JSON.stringify(summary, null, '\t')}\n`);
|
||||||
|
fs.writeFileSync(path.join(run_dir, 'summary.md'), render_markdown(summary));
|
||||||
|
|
||||||
|
return summary;
|
||||||
|
|
||||||
|
/** @param {Frame} frame */
|
||||||
|
function get_frame_index(frame) {
|
||||||
|
const key = frame_key(frame);
|
||||||
|
const existing = frame_indices.get(key);
|
||||||
|
if (existing !== undefined) return existing;
|
||||||
|
|
||||||
|
const index = frames.length;
|
||||||
|
const location = frame.url ? ` (${frame.url}:${frame.line})` : '';
|
||||||
|
frames.push({
|
||||||
|
name: `${frame.function_name}${location}`,
|
||||||
|
...(frame.url ? { file: frame.url, line: frame.line, col: frame.column } : {})
|
||||||
|
});
|
||||||
|
frame_indices.set(key, index);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} leaf_id
|
||||||
|
* @param {Map<number, any>} nodes_by_id
|
||||||
|
* @param {Map<number, number>} parents
|
||||||
|
* @returns {Frame[]}
|
||||||
|
*/
|
||||||
|
function get_stack(leaf_id, nodes_by_id, parents) {
|
||||||
|
/** @type {Frame[]} */
|
||||||
|
const stack = [];
|
||||||
|
const seen = new Set();
|
||||||
|
let id = leaf_id;
|
||||||
|
|
||||||
|
while (typeof id === 'number' && !seen.has(id)) {
|
||||||
|
seen.add(id);
|
||||||
|
const node = nodes_by_id.get(id);
|
||||||
|
if (!node) break;
|
||||||
|
|
||||||
|
const call_frame = node.callFrame || {};
|
||||||
|
stack.push({
|
||||||
|
function_name: call_frame.functionName || '(anonymous)',
|
||||||
|
url: normalize_url(call_frame.url || ''),
|
||||||
|
line: typeof call_frame.lineNumber === 'number' ? call_frame.lineNumber + 1 : 0,
|
||||||
|
column: typeof call_frame.columnNumber === 'number' ? call_frame.columnNumber + 1 : 0
|
||||||
|
});
|
||||||
|
id = parents.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack.reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {string} url */
|
||||||
|
function normalize_url(url) {
|
||||||
|
if (!url) return '';
|
||||||
|
|
||||||
|
let pathname = url.replace(/^\/\@fs\//, '/').replace(/[?#].*$/, '');
|
||||||
|
if (pathname.startsWith('file://')) {
|
||||||
|
try {
|
||||||
|
pathname = fileURLToPath(pathname);
|
||||||
|
} catch {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.isAbsolute(pathname)) {
|
||||||
|
const relative = path.relative(root, pathname);
|
||||||
|
if (!relative.startsWith('..') && !path.isAbsolute(relative)) {
|
||||||
|
pathname = relative;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathname.replaceAll(path.sep, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {Frame} frame */
|
||||||
|
function frame_key(frame) {
|
||||||
|
return `${frame.function_name}\0${frame.url}\0${frame.line}\0${frame.column}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Map<string, Hotspot>} collection
|
||||||
|
* @param {string} key
|
||||||
|
* @param {Frame} frame
|
||||||
|
*/
|
||||||
|
function get_hotspot(collection, key, frame) {
|
||||||
|
let hotspot = collection.get(key);
|
||||||
|
if (!hotspot) {
|
||||||
|
hotspot = { ...frame, self: 0, inclusive: 0 };
|
||||||
|
collection.set(key, hotspot);
|
||||||
|
}
|
||||||
|
return hotspot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Map<string, Hotspot>} collection
|
||||||
|
* @param {number} total
|
||||||
|
*/
|
||||||
|
function rank(collection, total) {
|
||||||
|
return [...collection.values()]
|
||||||
|
.map((hotspot) => ({
|
||||||
|
function: hotspot.function_name,
|
||||||
|
url: hotspot.url,
|
||||||
|
line: hotspot.line,
|
||||||
|
column: hotspot.column,
|
||||||
|
self_microseconds: hotspot.self,
|
||||||
|
self_percent: (hotspot.self * 100) / total,
|
||||||
|
inclusive_microseconds: hotspot.inclusive,
|
||||||
|
inclusive_percent: (hotspot.inclusive * 100) / total
|
||||||
|
}))
|
||||||
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
b.self_microseconds - a.self_microseconds ||
|
||||||
|
b.inclusive_microseconds - a.inclusive_microseconds
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {ReturnType<typeof analyze_compiler_profiles>} summary */
|
||||||
|
function render_markdown(summary) {
|
||||||
|
const lines = [
|
||||||
|
'# Svelte compiler CPU profile',
|
||||||
|
'',
|
||||||
|
'Open `flamegraph.speedscope.json` in [Speedscope](https://www.speedscope.app/) for the interactive flame graph.',
|
||||||
|
'',
|
||||||
|
'## Coverage',
|
||||||
|
'',
|
||||||
|
'| Metric | Value |',
|
||||||
|
'| --- | ---: |',
|
||||||
|
`| Raw profiles | ${summary.profile_files} |`,
|
||||||
|
`| All profiled CPU time | ${format_time(summary.total_time_microseconds)} |`,
|
||||||
|
`| Compiler-active CPU time | ${format_time(summary.compiler_time_microseconds)} |`,
|
||||||
|
`| Compiler share | ${summary.compiler_share_percent.toFixed(2)}% |`,
|
||||||
|
`| All-process garbage collection | ${format_time(summary.garbage_collection_time_microseconds)} |`,
|
||||||
|
'',
|
||||||
|
'Compiler-active time includes external callees while a compiler frame is on the stack. Garbage collection is reported for context but cannot be attributed to compiler stacks by V8.',
|
||||||
|
'',
|
||||||
|
'## Top Self Hotspots',
|
||||||
|
'',
|
||||||
|
'| Rank | Function | Location | Self | Self % | Inclusive | Inclusive % |',
|
||||||
|
'| ---: | --- | --- | ---: | ---: | ---: | ---: |'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [index, row] of summary.hotspots.slice(0, 50).entries()) {
|
||||||
|
lines.push(render_row(index, row));
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.push(
|
||||||
|
'',
|
||||||
|
'## Top Files',
|
||||||
|
'',
|
||||||
|
'| Rank | File | Self | Self % | Inclusive | Inclusive % |',
|
||||||
|
'| ---: | --- | ---: | ---: | ---: | ---: |'
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const [index, row] of summary.files.slice(0, 50).entries()) {
|
||||||
|
lines.push(
|
||||||
|
`| ${index + 1} | ${escape_cell(row.function)} | ${format_time(row.self_microseconds)} | ${row.self_percent.toFixed(2)}% | ${format_time(row.inclusive_microseconds)} | ${row.inclusive_percent.toFixed(2)}% |`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${lines.join('\n')}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {number} index @param {ReturnType<typeof rank>[number]} row */
|
||||||
|
function render_row(index, row) {
|
||||||
|
const location = row.url ? `${row.url}:${row.line}:${row.column}` : '(native)';
|
||||||
|
return `| ${index + 1} | ${escape_cell(row.function)} | ${escape_cell(location)} | ${format_time(row.self_microseconds)} | ${row.self_percent.toFixed(2)}% | ${format_time(row.inclusive_microseconds)} | ${row.inclusive_percent.toFixed(2)}% |`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {number} microseconds */
|
||||||
|
function format_time(microseconds) {
|
||||||
|
return `${(microseconds / 1000).toFixed(1)} ms`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {string} value */
|
||||||
|
function escape_cell(value) {
|
||||||
|
return value.replaceAll('|', '\\|');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||||
|
const run_dir = process.argv[2];
|
||||||
|
if (!run_dir) {
|
||||||
|
console.error('Usage: node benchmarking/analyze-compiler-profile.js <profile-run-directory>');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
analyze_compiler_profiles(path.resolve(run_dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{ function_name: string, url: string, line: number, column: number }} Frame
|
||||||
|
* @typedef {Frame & { self: number, inclusive: number }} Hotspot
|
||||||
|
*/
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import { parser_benchmarks } from './parser.bench.js';
|
||||||
|
|
||||||
|
export const compiler_benchmarks = parser_benchmarks;
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
import { parse } from '../../../packages/svelte/src/compiler/phases/1-parse/index.js';
|
||||||
|
import { fastest_test } from '../../utils.js';
|
||||||
|
|
||||||
|
const elements_source = Array.from(
|
||||||
|
{ length: 1000 },
|
||||||
|
(_, i) =>
|
||||||
|
`<!-- item ${i} --><section data-index="${i}" class="card card-${i}" title="plain text ${i}"><h2>Item ${i} has a reasonably long entity-free text value</h2><input disabled value="prefix {value} suffix"><textarea>plain {value} text</textarea></section>`
|
||||||
|
).join('\n');
|
||||||
|
|
||||||
|
const script_style_source = `<script>
|
||||||
|
// line comment
|
||||||
|
/* block comment */
|
||||||
|
const value = 42;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
${Array.from(
|
||||||
|
{ length: 1000 },
|
||||||
|
(_, i) => `.item-${i} { /* property ${i} */ color: red; margin-inline: ${i}px; }`
|
||||||
|
).join('\n')}
|
||||||
|
</style>`;
|
||||||
|
|
||||||
|
const typescript_source = `${Array.from(
|
||||||
|
{ length: 1000 },
|
||||||
|
(_, i) => `<div data-index="${i}">Item ${i}</div>`
|
||||||
|
).join('\n')}
|
||||||
|
{value as number}
|
||||||
|
<script lang="ts">
|
||||||
|
let value: number = 42;
|
||||||
|
</script>${' \n'.repeat(1000)}`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} label
|
||||||
|
* @param {string} source
|
||||||
|
* @param {number} iterations
|
||||||
|
*/
|
||||||
|
function create_parser_benchmark(label, source, iterations) {
|
||||||
|
return {
|
||||||
|
label,
|
||||||
|
fn: async () => {
|
||||||
|
for (let i = 0; i < iterations; i++) {
|
||||||
|
parse(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await fastest_test(10, () => {
|
||||||
|
for (let i = 0; i < iterations; i++) {
|
||||||
|
parse(source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const parser_benchmarks = [
|
||||||
|
create_parser_benchmark('parser_elements', elements_source, 5),
|
||||||
|
create_parser_benchmark('parser_script_style', script_style_source, 50),
|
||||||
|
create_parser_benchmark('parser_typescript', typescript_source, 25)
|
||||||
|
];
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
import assert from 'node:assert';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
import { block } from '../../../../packages/svelte/src/internal/client/reactivity/effects.js';
|
||||||
|
|
||||||
|
// Like `kairo_broad`, but each derived is also read by a block effect, as
|
||||||
|
// happens with e.g. `{#if derived}` in a component. Measures our #traverse perf better.
|
||||||
|
export default () => {
|
||||||
|
let head = $.state(0);
|
||||||
|
let last = head;
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
|
const destroy = $.effect_root(() => {
|
||||||
|
for (let i = 0; i < 50; i++) {
|
||||||
|
let current = $.derived(() => {
|
||||||
|
return $.get(head) + i;
|
||||||
|
});
|
||||||
|
let current2 = $.derived(() => {
|
||||||
|
return $.get(current) + 1;
|
||||||
|
});
|
||||||
|
block(() => {
|
||||||
|
$.get(current2);
|
||||||
|
});
|
||||||
|
$.render_effect(() => {
|
||||||
|
$.get(current2);
|
||||||
|
counter++;
|
||||||
|
});
|
||||||
|
last = current2;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy,
|
||||||
|
run() {
|
||||||
|
$.flush(() => {
|
||||||
|
$.set(head, 1);
|
||||||
|
});
|
||||||
|
counter = 0;
|
||||||
|
for (let i = 0; i < 50; i++) {
|
||||||
|
$.flush(() => {
|
||||||
|
$.set(head, i);
|
||||||
|
});
|
||||||
|
assert.equal($.get(last), i + 50);
|
||||||
|
}
|
||||||
|
assert.equal(counter, 50 * 50);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
import assert from 'node:assert';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
import { block } from '../../../../packages/svelte/src/internal/client/reactivity/effects.js';
|
||||||
|
|
||||||
|
let len = 50;
|
||||||
|
const iter = 50;
|
||||||
|
|
||||||
|
// Like `kairo_deep`, but the derived chain is also read by a block effect, as
|
||||||
|
// happens with e.g. `{#if derived}` in a component. Measures our #traverse perf better.
|
||||||
|
export default () => {
|
||||||
|
let head = $.state(0);
|
||||||
|
let current = head;
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
let c = current;
|
||||||
|
current = $.derived(() => {
|
||||||
|
return $.get(c) + 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
|
const destroy = $.effect_root(() => {
|
||||||
|
block(() => {
|
||||||
|
$.get(current);
|
||||||
|
});
|
||||||
|
|
||||||
|
$.render_effect(() => {
|
||||||
|
$.get(current);
|
||||||
|
counter++;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy,
|
||||||
|
run() {
|
||||||
|
$.flush(() => {
|
||||||
|
$.set(head, 1);
|
||||||
|
});
|
||||||
|
counter = 0;
|
||||||
|
for (let i = 0; i < iter; i++) {
|
||||||
|
$.flush(() => {
|
||||||
|
$.set(head, i);
|
||||||
|
});
|
||||||
|
assert.equal($.get(current), len + i);
|
||||||
|
}
|
||||||
|
assert.equal(counter, iter);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -0,0 +1,741 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Benchmark comparison</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
|
font-family:
|
||||||
|
Inter,
|
||||||
|
ui-sans-serif,
|
||||||
|
system-ui,
|
||||||
|
-apple-system,
|
||||||
|
BlinkMacSystemFont,
|
||||||
|
'Segoe UI',
|
||||||
|
sans-serif;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
background: #f6f8fa;
|
||||||
|
color: #1f2328;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: #f6f8fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
width: min(1600px, 100%);
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 40px clamp(16px, 3vw, 48px) 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
font-size: clamp(28px, 4vw, 48px);
|
||||||
|
letter-spacing: -0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin-bottom: 14px;
|
||||||
|
font-size: 18px;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.intro {
|
||||||
|
max-width: 780px;
|
||||||
|
margin-bottom: 28px;
|
||||||
|
color: #59636e;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card,
|
||||||
|
.panel {
|
||||||
|
border: 1px solid #d0d7de;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0 8px 24px rgb(140 149 159 / 16%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
min-height: 112px;
|
||||||
|
padding: 18px 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-label {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
color: #59636e;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-value {
|
||||||
|
font-size: 21px;
|
||||||
|
font-weight: 750;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-detail {
|
||||||
|
margin-top: 7px;
|
||||||
|
color: #59636e;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: end;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 20px;
|
||||||
|
padding: 18px 20px;
|
||||||
|
border-bottom: 1px solid #d8dee4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-heading h2,
|
||||||
|
.panel-heading p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.help {
|
||||||
|
max-width: 720px;
|
||||||
|
color: #59636e;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 14px 20px;
|
||||||
|
border-bottom: 1px solid #d8dee4;
|
||||||
|
background: #f6f8fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: #59636e;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
max-width: 250px;
|
||||||
|
padding: 7px 30px 7px 9px;
|
||||||
|
border: 1px solid #afb8c1;
|
||||||
|
border-radius: 5px;
|
||||||
|
background: #ffffff;
|
||||||
|
color: #1f2328;
|
||||||
|
font: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-wrap {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: separate;
|
||||||
|
border-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
padding: 11px 14px;
|
||||||
|
border-right: 1px solid #d8dee4;
|
||||||
|
border-bottom: 1px solid #d8dee4;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
th:last-child,
|
||||||
|
td:last-child {
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:last-child td {
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background: #f6f8fa;
|
||||||
|
color: #59636e;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
th button {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
font: inherit;
|
||||||
|
letter-spacing: inherit;
|
||||||
|
text-align: inherit;
|
||||||
|
text-transform: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
th button:hover,
|
||||||
|
th button:focus-visible {
|
||||||
|
color: #1f2328;
|
||||||
|
}
|
||||||
|
|
||||||
|
.standings td:nth-child(n + 2),
|
||||||
|
.standings th:nth-child(n + 2) {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rank {
|
||||||
|
display: inline-grid;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
margin-right: 10px;
|
||||||
|
place-items: center;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #eaeef2;
|
||||||
|
color: #424a53;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 750;
|
||||||
|
}
|
||||||
|
|
||||||
|
.branch-name,
|
||||||
|
.benchmark-name {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.benchmark-table {
|
||||||
|
min-width: max(900px, 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.benchmark-table thead {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.benchmark-table th:first-child,
|
||||||
|
.benchmark-table td:first-child {
|
||||||
|
position: sticky;
|
||||||
|
left: 0;
|
||||||
|
z-index: 2;
|
||||||
|
min-width: 220px;
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.benchmark-table th:first-child {
|
||||||
|
z-index: 4;
|
||||||
|
background: #f6f8fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.benchmark-table th:nth-child(2),
|
||||||
|
.benchmark-table td:nth-child(2) {
|
||||||
|
min-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.benchmark-table th:not(:first-child),
|
||||||
|
.benchmark-table td:not(:first-child) {
|
||||||
|
min-width: 175px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric {
|
||||||
|
position: relative;
|
||||||
|
isolation: isolate;
|
||||||
|
background: hsl(var(--heat, 210) 74% 94%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric::after {
|
||||||
|
position: absolute;
|
||||||
|
z-index: -1;
|
||||||
|
inset: auto 0 0;
|
||||||
|
height: 3px;
|
||||||
|
background: hsl(var(--heat, 210) 65% 43%);
|
||||||
|
content: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
.time {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 750;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delta {
|
||||||
|
margin-left: 7px;
|
||||||
|
color: #424a53;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondary {
|
||||||
|
margin-top: 5px;
|
||||||
|
color: #59636e;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.winner {
|
||||||
|
color: #1a7f37;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.missing {
|
||||||
|
background: #f6f8fa;
|
||||||
|
color: #6e7781;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
color: #6e7781;
|
||||||
|
font-size: 12px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 760px) {
|
||||||
|
main {
|
||||||
|
padding-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-heading {
|
||||||
|
align-items: start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls,
|
||||||
|
label {
|
||||||
|
align-items: stretch;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
max-width: none;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<h1>Benchmark comparison</h1>
|
||||||
|
<p class="intro">
|
||||||
|
Runtime results across branches. Green cells are fastest for an entry and red cells expose
|
||||||
|
the largest regressions. Overall runtime normalizes every benchmark to its fastest result
|
||||||
|
before averaging, so long-running entries do not outweigh short ones.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<section class="summary" id="summary" aria-label="Comparison summary"></section>
|
||||||
|
|
||||||
|
<section class="panel">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<div>
|
||||||
|
<h2>Branch standings</h2>
|
||||||
|
<p class="help">
|
||||||
|
Wins count the fastest branch for each comparable entry. Normalized runtime is the
|
||||||
|
average slowdown against each entry's fastest result; lower is better. Click a heading
|
||||||
|
to sort.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="standings">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><button type="button" data-standing-sort="name">Branch</button></th>
|
||||||
|
<th><button type="button" data-standing-sort="wins">Wins</button></th>
|
||||||
|
<th>
|
||||||
|
<button type="button" data-standing-sort="score">Normalized runtime</button>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="standings"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="panel">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<div>
|
||||||
|
<h2>Results by benchmark</h2>
|
||||||
|
<p class="help">
|
||||||
|
Each cell shows runtime, difference from the winner, and GC time. Missing entries are
|
||||||
|
excluded from both standings.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<label
|
||||||
|
>Sort benchmarks
|
||||||
|
<select id="benchmark-sort"></select
|
||||||
|
></label>
|
||||||
|
<label
|
||||||
|
>Order branches
|
||||||
|
<select id="branch-order">
|
||||||
|
<option value="name">Branch name</option>
|
||||||
|
<option value="wins">Overall winner by wins</option>
|
||||||
|
<option value="score" selected>Overall winner by normalized runtime</option>
|
||||||
|
</select></label
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="benchmark-table" id="benchmark-table"></table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<footer id="generated"></footer>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script type="application/json" id="report-data">
|
||||||
|
%%REPORT_DATA%%
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
const report = JSON.parse(document.querySelector('#report-data').textContent);
|
||||||
|
const number = new Intl.NumberFormat('en', {
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
minimumFractionDigits: 2
|
||||||
|
});
|
||||||
|
const score_number = new Intl.NumberFormat('en', {
|
||||||
|
maximumFractionDigits: 3,
|
||||||
|
minimumFractionDigits: 3
|
||||||
|
});
|
||||||
|
|
||||||
|
function analyze(benchmark) {
|
||||||
|
const complete =
|
||||||
|
benchmark.values.length === report.branches.length &&
|
||||||
|
benchmark.values.every(function (value) {
|
||||||
|
return value !== null && Number.isFinite(value.time) && value.time > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!complete) return { comparable: false, min: 0, max: 0, winners: [], ratios: [] };
|
||||||
|
|
||||||
|
const times = benchmark.values.map(function (value) {
|
||||||
|
return value.time;
|
||||||
|
});
|
||||||
|
const min = Math.min.apply(null, times);
|
||||||
|
const max = Math.max.apply(null, times);
|
||||||
|
const winners = [];
|
||||||
|
|
||||||
|
times.forEach(function (time, index) {
|
||||||
|
if (time === min) winners.push(index);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
comparable: true,
|
||||||
|
min: min,
|
||||||
|
max: max,
|
||||||
|
winners: winners,
|
||||||
|
ratios: times.map(function (time) {
|
||||||
|
return time / min;
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const analyzed = report.benchmarks.map(function (benchmark, index) {
|
||||||
|
return { benchmark: benchmark, stats: analyze(benchmark), index: index };
|
||||||
|
});
|
||||||
|
const comparable = analyzed.filter(function (entry) {
|
||||||
|
return entry.stats.comparable;
|
||||||
|
});
|
||||||
|
const standings = report.branches.map(function (name, index) {
|
||||||
|
let wins = 0;
|
||||||
|
let score = 0;
|
||||||
|
|
||||||
|
comparable.forEach(function (entry) {
|
||||||
|
if (entry.stats.winners.includes(index)) wins += 1;
|
||||||
|
score += entry.stats.ratios[index];
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: name,
|
||||||
|
index: index,
|
||||||
|
wins: wins,
|
||||||
|
score: comparable.length === 0 ? Infinity : score / comparable.length
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
function compare_name(a, b) {
|
||||||
|
return a.name.localeCompare(b.name, undefined, { numeric: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function order_standings(key, direction) {
|
||||||
|
return standings.slice().sort(function (a, b) {
|
||||||
|
let result;
|
||||||
|
if (key === 'name') result = compare_name(a, b);
|
||||||
|
else result = a[key] - b[key];
|
||||||
|
return result === 0 ? compare_name(a, b) : result * direction;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function best(key, direction) {
|
||||||
|
const ordered = order_standings(key, direction);
|
||||||
|
if (ordered.length === 0) return [];
|
||||||
|
return ordered.filter(function (entry) {
|
||||||
|
return entry[key] === ordered[0][key];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function names(entries) {
|
||||||
|
return entries
|
||||||
|
.map(function (entry) {
|
||||||
|
return entry.name;
|
||||||
|
})
|
||||||
|
.join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function make(tag, class_name, text) {
|
||||||
|
const node = document.createElement(tag);
|
||||||
|
if (class_name) node.className = class_name;
|
||||||
|
if (text !== undefined) node.textContent = text;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
const wins_best = best('wins', -1);
|
||||||
|
const score_best = best('score', 1);
|
||||||
|
const summary = document.querySelector('#summary');
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label: 'Most benchmark wins',
|
||||||
|
value: comparable.length === 0 ? 'No comparable results' : names(wins_best),
|
||||||
|
detail:
|
||||||
|
comparable.length === 0
|
||||||
|
? ''
|
||||||
|
: wins_best[0].wins + ' of ' + comparable.length + ' entries'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Best normalized runtime',
|
||||||
|
value:
|
||||||
|
score_best.length === 0 || !Number.isFinite(score_best[0].score)
|
||||||
|
? 'No comparable results'
|
||||||
|
: names(score_best),
|
||||||
|
detail:
|
||||||
|
score_best.length === 0 || !Number.isFinite(score_best[0].score)
|
||||||
|
? ''
|
||||||
|
: score_number.format(score_best[0].score) + 'x average runtime'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Coverage',
|
||||||
|
value: comparable.length + ' comparable entries',
|
||||||
|
detail:
|
||||||
|
report.branches.length +
|
||||||
|
' branches, ' +
|
||||||
|
(report.benchmarks.length - comparable.length) +
|
||||||
|
' incomplete entries'
|
||||||
|
}
|
||||||
|
].forEach(function (item) {
|
||||||
|
const card = make('article', 'card');
|
||||||
|
card.append(
|
||||||
|
make('div', 'card-label', item.label),
|
||||||
|
make('div', 'card-value', item.value),
|
||||||
|
make('div', 'card-detail', item.detail)
|
||||||
|
);
|
||||||
|
summary.append(card);
|
||||||
|
});
|
||||||
|
|
||||||
|
let standing_sort = { key: 'score', direction: 1 };
|
||||||
|
|
||||||
|
function render_standings() {
|
||||||
|
const body = document.querySelector('#standings');
|
||||||
|
body.replaceChildren();
|
||||||
|
const score_order = order_standings('score', 1);
|
||||||
|
|
||||||
|
order_standings(standing_sort.key, standing_sort.direction).forEach(function (entry) {
|
||||||
|
const row = document.createElement('tr');
|
||||||
|
const branch = make('td');
|
||||||
|
branch.append(
|
||||||
|
make('span', 'rank', String(score_order.indexOf(entry) + 1)),
|
||||||
|
make('span', 'branch-name', entry.name)
|
||||||
|
);
|
||||||
|
row.append(
|
||||||
|
branch,
|
||||||
|
make('td', '', String(entry.wins)),
|
||||||
|
make(
|
||||||
|
'td',
|
||||||
|
'',
|
||||||
|
Number.isFinite(entry.score) ? score_number.format(entry.score) + 'x' : 'n/a'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
body.append(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('[data-standing-sort]').forEach(function (button) {
|
||||||
|
const active = button.dataset.standingSort === standing_sort.key;
|
||||||
|
button
|
||||||
|
.closest('th')
|
||||||
|
.setAttribute(
|
||||||
|
'aria-sort',
|
||||||
|
active ? (standing_sort.direction === 1 ? 'ascending' : 'descending') : 'none'
|
||||||
|
);
|
||||||
|
button.textContent =
|
||||||
|
button.dataset.standingSort === 'name'
|
||||||
|
? 'Branch'
|
||||||
|
: button.dataset.standingSort === 'wins'
|
||||||
|
? 'Wins'
|
||||||
|
: 'Normalized runtime';
|
||||||
|
if (active) button.textContent += standing_sort.direction === 1 ? ' ↑' : ' ↓';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('[data-standing-sort]').forEach(function (button) {
|
||||||
|
button.addEventListener('click', function () {
|
||||||
|
const key = button.dataset.standingSort;
|
||||||
|
if (standing_sort.key === key) standing_sort.direction *= -1;
|
||||||
|
else standing_sort = { key: key, direction: key === 'wins' ? -1 : 1 };
|
||||||
|
render_standings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const benchmark_sort = document.querySelector('#benchmark-sort');
|
||||||
|
[
|
||||||
|
['original', 'Original run order'],
|
||||||
|
['name', 'Benchmark name'],
|
||||||
|
['winner', 'Winner for entry'],
|
||||||
|
['spread', 'Largest spread']
|
||||||
|
]
|
||||||
|
.concat(
|
||||||
|
report.branches.map(function (branch, index) {
|
||||||
|
return ['branch:' + index, branch + ': slowest relative result'];
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.forEach(function (option) {
|
||||||
|
const node = make('option', '', option[1]);
|
||||||
|
node.value = option[0];
|
||||||
|
benchmark_sort.append(node);
|
||||||
|
});
|
||||||
|
|
||||||
|
function branch_order() {
|
||||||
|
const key = document.querySelector('#branch-order').value;
|
||||||
|
if (key === 'name') return order_standings('name', 1);
|
||||||
|
if (key === 'wins') return order_standings('wins', -1);
|
||||||
|
return order_standings('score', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function benchmark_order() {
|
||||||
|
const key = benchmark_sort.value;
|
||||||
|
return analyzed.slice().sort(function (a, b) {
|
||||||
|
if (key === 'original') return a.index - b.index;
|
||||||
|
if (key === 'name') return compare_name(a.benchmark, b.benchmark);
|
||||||
|
if (key === 'winner') {
|
||||||
|
const a_name = a.stats.comparable ? report.branches[a.stats.winners[0]] : '\uffff';
|
||||||
|
const b_name = b.stats.comparable ? report.branches[b.stats.winners[0]] : '\uffff';
|
||||||
|
return a_name.localeCompare(b_name) || compare_name(a.benchmark, b.benchmark);
|
||||||
|
}
|
||||||
|
if (key === 'spread') {
|
||||||
|
const a_spread = a.stats.comparable ? a.stats.max / a.stats.min : -1;
|
||||||
|
const b_spread = b.stats.comparable ? b.stats.max / b.stats.min : -1;
|
||||||
|
return b_spread - a_spread || compare_name(a.benchmark, b.benchmark);
|
||||||
|
}
|
||||||
|
|
||||||
|
const branch = Number(key.slice('branch:'.length));
|
||||||
|
const a_ratio = a.stats.comparable ? a.stats.ratios[branch] : -1;
|
||||||
|
const b_ratio = b.stats.comparable ? b.stats.ratios[branch] : -1;
|
||||||
|
return b_ratio - a_ratio || compare_name(a.benchmark, b.benchmark);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function render_benchmarks() {
|
||||||
|
const table = document.querySelector('#benchmark-table');
|
||||||
|
const branches = branch_order();
|
||||||
|
const head = document.createElement('thead');
|
||||||
|
const head_row = document.createElement('tr');
|
||||||
|
head_row.append(make('th', '', 'Benchmark'), make('th', '', 'Winner'));
|
||||||
|
branches.forEach(function (branch) {
|
||||||
|
head_row.append(make('th', '', branch.name));
|
||||||
|
});
|
||||||
|
head.append(head_row);
|
||||||
|
|
||||||
|
const body = document.createElement('tbody');
|
||||||
|
benchmark_order().forEach(function (entry) {
|
||||||
|
const row = document.createElement('tr');
|
||||||
|
row.append(make('td', 'benchmark-name', entry.benchmark.name));
|
||||||
|
|
||||||
|
const winner_names = entry.stats.winners.map(function (index) {
|
||||||
|
return report.branches[index];
|
||||||
|
});
|
||||||
|
row.append(
|
||||||
|
make(
|
||||||
|
'td',
|
||||||
|
winner_names.length === 0 ? 'missing' : 'winner',
|
||||||
|
winner_names.length === 0 ? 'Incomplete' : winner_names.join(', ')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
branches.forEach(function (branch) {
|
||||||
|
const value = entry.benchmark.values[branch.index];
|
||||||
|
if (value === null || !Number.isFinite(value.time)) {
|
||||||
|
row.append(make('td', 'missing', 'Not available'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cell = make('td', entry.stats.comparable ? 'metric' : 'missing');
|
||||||
|
const time = make('span', 'time', number.format(value.time) + ' ms');
|
||||||
|
cell.append(time);
|
||||||
|
|
||||||
|
if (entry.stats.comparable) {
|
||||||
|
const ratio = entry.stats.ratios[branch.index];
|
||||||
|
const heat =
|
||||||
|
entry.stats.max === entry.stats.min
|
||||||
|
? 0
|
||||||
|
: (value.time - entry.stats.min) / (entry.stats.max - entry.stats.min);
|
||||||
|
cell.style.setProperty('--heat', String(Math.round(142 - heat * 137)));
|
||||||
|
cell.append(
|
||||||
|
make(
|
||||||
|
'span',
|
||||||
|
'delta',
|
||||||
|
ratio === 1 ? 'fastest' : '+' + number.format((ratio - 1) * 100) + '%'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gc = Number.isFinite(value.gc_time)
|
||||||
|
? number.format(value.gc_time) + ' ms'
|
||||||
|
: 'n/a';
|
||||||
|
cell.append(make('div', 'secondary', 'GC ' + gc));
|
||||||
|
row.append(cell);
|
||||||
|
});
|
||||||
|
|
||||||
|
body.append(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
table.replaceChildren(head, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
benchmark_sort.addEventListener('change', render_benchmarks);
|
||||||
|
document.querySelector('#branch-order').addEventListener('change', render_benchmarks);
|
||||||
|
document.querySelector('#generated').textContent =
|
||||||
|
'Generated ' + new Date(report.generated_at).toLocaleString();
|
||||||
|
|
||||||
|
render_standings();
|
||||||
|
render_benchmarks();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -1,18 +1,67 @@
|
|||||||
|
import { fork } from 'node:child_process';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
import { reactivity_benchmarks } from '../benchmarks/reactivity/index.js';
|
import { reactivity_benchmarks } from '../benchmarks/reactivity/index.js';
|
||||||
import { with_cpu_profile } from '../utils.js';
|
import { with_cpu_profile } from '../utils.js';
|
||||||
|
|
||||||
const results = [];
|
const PROFILE_DIR = process.env.BENCH_PROFILE_DIR ?? null;
|
||||||
const PROFILE_DIR = process.env.BENCH_PROFILE_DIR;
|
const single = process.env.BENCH_SINGLE;
|
||||||
|
|
||||||
for (let i = 0; i < reactivity_benchmarks.length; i += 1) {
|
if (single) {
|
||||||
const benchmark = reactivity_benchmarks[i];
|
// child mode — run a single benchmark and report the result to the parent
|
||||||
|
const benchmark = reactivity_benchmarks.find((b) => b.label === single);
|
||||||
|
|
||||||
process.stderr.write(`Running ${i + 1}/${reactivity_benchmarks.length} ${benchmark.label} `);
|
if (!benchmark) {
|
||||||
results.push({
|
throw new Error(`Unknown benchmark ${single}`);
|
||||||
benchmark: benchmark.label,
|
}
|
||||||
...(await with_cpu_profile(PROFILE_DIR, benchmark.label, () => benchmark.fn()))
|
|
||||||
});
|
const result = await with_cpu_profile(PROFILE_DIR, benchmark.label, () => benchmark.fn());
|
||||||
process.stderr.write('\x1b[2K\r');
|
|
||||||
}
|
// exit via the callback so the message is guaranteed to be delivered
|
||||||
|
/** @type {NodeJS.Process} */ (process).send(result, () => process.exit(0));
|
||||||
|
} else {
|
||||||
|
// parent mode — run every benchmark in its own child process, so that
|
||||||
|
// heap/GC/JIT state from one benchmark cannot contaminate the others
|
||||||
|
const filename = fileURLToPath(import.meta.url);
|
||||||
|
const results = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < reactivity_benchmarks.length; i += 1) {
|
||||||
|
const benchmark = reactivity_benchmarks[i];
|
||||||
|
|
||||||
|
process.stderr.write(`Running ${i + 1}/${reactivity_benchmarks.length} ${benchmark.label} `);
|
||||||
|
|
||||||
|
const result = await new Promise((fulfil, reject) => {
|
||||||
|
const child = fork(filename, [], {
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
BENCH_SINGLE: benchmark.label
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @type {object | null} */
|
||||||
|
let message_received = null;
|
||||||
|
|
||||||
process.send(results);
|
child.on('message', (message) => {
|
||||||
|
message_received = /** @type {object} */ (message);
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('error', reject);
|
||||||
|
|
||||||
|
child.on('exit', (code) => {
|
||||||
|
if (message_received === null) {
|
||||||
|
reject(new Error(`benchmark ${benchmark.label} exited with code ${code}`));
|
||||||
|
} else {
|
||||||
|
fulfil(message_received);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
results.push({
|
||||||
|
benchmark: benchmark.label,
|
||||||
|
.../** @type {object} */ (result)
|
||||||
|
});
|
||||||
|
|
||||||
|
process.stderr.write('\x1b[2K\r');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {NodeJS.Process} */ (process).send(results);
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,43 @@
|
|||||||
|
# Compiler CPU profiling
|
||||||
|
|
||||||
|
Run the full test suite with V8 CPU profiling enabled in every Vitest worker:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pnpm profile:compiler
|
||||||
|
```
|
||||||
|
|
||||||
|
Arguments are passed to `pnpm test`, so a smaller smoke run can target a suite:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pnpm profile:compiler snapshot
|
||||||
|
```
|
||||||
|
|
||||||
|
Each run is stored under `benchmarking/.profiles/compiler-tests/<timestamp>`. Set
|
||||||
|
`SVELTE_PROFILE_NAME` to give a run a stable name; existing runs are never overwritten.
|
||||||
|
`benchmarking/.profiles/compiler-tests/latest.txt` contains the latest successful run name.
|
||||||
|
|
||||||
|
Each run contains:
|
||||||
|
|
||||||
|
- `raw/*.cpuprofile`: the original V8 profile from every Vitest worker
|
||||||
|
- `flamegraph.speedscope.json`: compiler-active stacks merged for use in
|
||||||
|
[Speedscope](https://www.speedscope.app/)
|
||||||
|
- `summary.md`: ranked self/inclusive hotspots and files
|
||||||
|
- `summary.json`: the same measurements for further analysis
|
||||||
|
- `manifest.json`: the command, revision, timestamps, and test result
|
||||||
|
|
||||||
|
The merged profile includes downstream callees while a compiler source frame is on the stack.
|
||||||
|
This captures parser, walker, and printer dependencies without including unrelated test runtime.
|
||||||
|
V8 reports garbage collection outside the originating stack, so the summary reports process-wide
|
||||||
|
GC separately rather than attributing it to the compiler.
|
||||||
|
|
||||||
|
The default sampling interval is 5 ms. It can be changed for shorter, focused runs:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
SVELTE_CPU_PROF_INTERVAL=1000 pnpm profile:compiler snapshot
|
||||||
|
```
|
||||||
|
|
||||||
|
Existing raw profiles can be analyzed again without rerunning tests:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
node benchmarking/analyze-compiler-profile.js benchmarking/.profiles/compiler-tests/<run>
|
||||||
|
```
|
||||||
@ -0,0 +1,94 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { analyze_compiler_profiles } from './analyze-compiler-profile.js';
|
||||||
|
|
||||||
|
const root = path.resolve(fileURLToPath(import.meta.url), '../..');
|
||||||
|
const profiles_root = path.join(root, 'benchmarking/.profiles/compiler-tests');
|
||||||
|
const requested_name = process.env.SVELTE_PROFILE_NAME;
|
||||||
|
const run_name = safe(requested_name || new Date().toISOString().replaceAll(':', '-'));
|
||||||
|
const run_dir = path.join(profiles_root, run_name);
|
||||||
|
const raw_dir = path.join(run_dir, 'raw');
|
||||||
|
const test_args = process.argv.slice(2);
|
||||||
|
const sampling_interval = process.env.SVELTE_CPU_PROF_INTERVAL || '5000';
|
||||||
|
|
||||||
|
if (fs.existsSync(run_dir)) {
|
||||||
|
console.error(`Profile run already exists: ${path.relative(root, run_dir)}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.mkdirSync(raw_dir, { recursive: true });
|
||||||
|
|
||||||
|
const revision = spawnSync('git', ['rev-parse', 'HEAD'], {
|
||||||
|
cwd: root,
|
||||||
|
encoding: 'utf8'
|
||||||
|
});
|
||||||
|
const started_at = new Date().toISOString();
|
||||||
|
const manifest_file = path.join(run_dir, 'manifest.json');
|
||||||
|
const command = [
|
||||||
|
'pnpm',
|
||||||
|
'test',
|
||||||
|
'--execArgv=--cpu-prof',
|
||||||
|
`--execArgv=--cpu-prof-dir=${raw_dir}`,
|
||||||
|
`--execArgv=--cpu-prof-interval=${sampling_interval}`,
|
||||||
|
...test_args
|
||||||
|
];
|
||||||
|
|
||||||
|
write_manifest({
|
||||||
|
command,
|
||||||
|
revision: revision.status === 0 ? revision.stdout.trim() : null,
|
||||||
|
started_at,
|
||||||
|
status: 'running'
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Compiler profiles will be written to ${path.relative(root, run_dir)}`);
|
||||||
|
|
||||||
|
const result = spawnSync(command[0], command.slice(1), {
|
||||||
|
cwd: root,
|
||||||
|
stdio: 'inherit'
|
||||||
|
});
|
||||||
|
|
||||||
|
let analysis_error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
analyze_compiler_profiles(run_dir);
|
||||||
|
fs.writeFileSync(path.join(profiles_root, 'latest.txt'), `${run_name}\n`);
|
||||||
|
} catch (error) {
|
||||||
|
analysis_error = error instanceof Error ? error.stack || error.message : String(error);
|
||||||
|
console.error(analysis_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
write_manifest({
|
||||||
|
command,
|
||||||
|
revision: revision.status === 0 ? revision.stdout.trim() : null,
|
||||||
|
started_at,
|
||||||
|
finished_at: new Date().toISOString(),
|
||||||
|
status: result.status === 0 && analysis_error === null ? 'completed' : 'failed',
|
||||||
|
test_exit_code: result.status,
|
||||||
|
test_signal: result.signal,
|
||||||
|
analysis_error
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
console.error(result.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status === 0 && analysis_error === null) {
|
||||||
|
console.log(
|
||||||
|
`Compiler flame graph: ${path.relative(root, path.join(run_dir, 'flamegraph.speedscope.json'))}`
|
||||||
|
);
|
||||||
|
console.log(`Compiler hotspot summary: ${path.relative(root, path.join(run_dir, 'summary.md'))}`);
|
||||||
|
} else {
|
||||||
|
process.exitCode = result.status || 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {string} value */
|
||||||
|
function safe(value) {
|
||||||
|
return value.replace(/[^a-z0-9._-]+/gi, '_');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {Record<string, unknown>} manifest */
|
||||||
|
function write_manifest(manifest) {
|
||||||
|
fs.writeFileSync(manifest_file, `${JSON.stringify(manifest, null, '\t')}\n`);
|
||||||
|
}
|
||||||
@ -1,94 +1,159 @@
|
|||||||
|
import { fork } from 'node:child_process';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
import * as $ from '../packages/svelte/src/internal/client/index.js';
|
import * as $ from '../packages/svelte/src/internal/client/index.js';
|
||||||
|
import { compiler_benchmarks } from './benchmarks/compiler/index.js';
|
||||||
import { reactivity_benchmarks } from './benchmarks/reactivity/index.js';
|
import { reactivity_benchmarks } from './benchmarks/reactivity/index.js';
|
||||||
import { ssr_benchmarks } from './benchmarks/ssr/index.js';
|
import { ssr_benchmarks } from './benchmarks/ssr/index.js';
|
||||||
import { with_cpu_profile } from './utils.js';
|
import { with_cpu_profile } from './utils.js';
|
||||||
|
|
||||||
// e.g. `pnpm bench kairo` to only run the kairo benchmarks
|
|
||||||
const filters = process.argv.slice(2);
|
|
||||||
|
|
||||||
const PROFILE_DIR = './benchmarking/.profiles';
|
const PROFILE_DIR = './benchmarking/.profiles';
|
||||||
|
|
||||||
const suites = [
|
const single = process.env.BENCH_SINGLE;
|
||||||
{
|
|
||||||
benchmarks: reactivity_benchmarks.filter(
|
|
||||||
(b) => filters.length === 0 || filters.some((f) => b.label.includes(f))
|
|
||||||
),
|
|
||||||
name: 'reactivity benchmarks'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
benchmarks: ssr_benchmarks.filter(
|
|
||||||
(b) => filters.length === 0 || filters.some((f) => b.label.includes(f))
|
|
||||||
),
|
|
||||||
name: 'server-side rendering benchmarks'
|
|
||||||
}
|
|
||||||
].filter((suite) => suite.benchmarks.length > 0);
|
|
||||||
|
|
||||||
if (suites.length === 0) {
|
|
||||||
console.log('No benchmarks matched provided filters');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const COLUMN_WIDTHS = [25, 9, 9];
|
|
||||||
const TOTAL_WIDTH = COLUMN_WIDTHS.reduce((a, b) => a + b);
|
|
||||||
|
|
||||||
const pad_right = (str, n) => str + ' '.repeat(n - str.length);
|
|
||||||
const pad_left = (str, n) => ' '.repeat(n - str.length) + str;
|
|
||||||
|
|
||||||
let total_time = 0;
|
if (single) {
|
||||||
let total_gc_time = 0;
|
// child mode — run a single benchmark and report the result to the parent
|
||||||
|
const benchmark = [...compiler_benchmarks, ...reactivity_benchmarks, ...ssr_benchmarks].find(
|
||||||
|
(b) => b.label === single
|
||||||
|
);
|
||||||
|
|
||||||
$.push({}, true);
|
if (!benchmark) {
|
||||||
|
throw new Error(`Unknown benchmark ${single}`);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
$.push({}, true);
|
||||||
for (const { benchmarks, name } of suites) {
|
|
||||||
let suite_time = 0;
|
const result = await with_cpu_profile(PROFILE_DIR, benchmark.label, () => benchmark.fn());
|
||||||
let suite_gc_time = 0;
|
|
||||||
|
$.pop();
|
||||||
|
|
||||||
|
// exit via the callback so the message is guaranteed to be delivered
|
||||||
|
/** @type {NodeJS.Process} */ (process).send(result, () => process.exit(0));
|
||||||
|
} else {
|
||||||
|
// parent mode — run every benchmark in its own child process, so that
|
||||||
|
// heap/GC/JIT state from one benchmark cannot contaminate the others
|
||||||
|
|
||||||
|
// e.g. `pnpm bench kairo` to only run the kairo benchmarks
|
||||||
|
const filters = process.argv.slice(2);
|
||||||
|
|
||||||
|
const suites = [
|
||||||
|
// Commenting out because we rarely need to run it
|
||||||
|
// {
|
||||||
|
// benchmarks: compiler_benchmarks.filter(
|
||||||
|
// (b) => filters.length === 0 || filters.some((f) => b.label.includes(f))
|
||||||
|
// ),
|
||||||
|
// name: 'compiler benchmarks'
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
benchmarks: reactivity_benchmarks.filter(
|
||||||
|
(b) => filters.length === 0 || filters.some((f) => b.label.includes(f))
|
||||||
|
),
|
||||||
|
name: 'reactivity benchmarks'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
benchmarks: ssr_benchmarks.filter(
|
||||||
|
(b) => filters.length === 0 || filters.some((f) => b.label.includes(f))
|
||||||
|
),
|
||||||
|
name: 'server-side rendering benchmarks'
|
||||||
|
}
|
||||||
|
].filter((suite) => suite.benchmarks.length > 0);
|
||||||
|
|
||||||
console.log(`\nRunning ${name}...\n`);
|
if (suites.length === 0) {
|
||||||
console.log(
|
console.log('No benchmarks matched provided filters');
|
||||||
pad_right('Benchmark', COLUMN_WIDTHS[0]) +
|
process.exit(1);
|
||||||
pad_left('Time', COLUMN_WIDTHS[1]) +
|
}
|
||||||
pad_left('GC time', COLUMN_WIDTHS[2])
|
|
||||||
);
|
|
||||||
console.log('='.repeat(TOTAL_WIDTH));
|
|
||||||
|
|
||||||
for (const benchmark of benchmarks) {
|
const filename = fileURLToPath(import.meta.url);
|
||||||
const results = await with_cpu_profile(PROFILE_DIR, benchmark.label, () => benchmark.fn());
|
|
||||||
|
/**
|
||||||
|
* @param {string} label
|
||||||
|
* @returns {Promise<{ time: number, gc_time: number }>}
|
||||||
|
*/
|
||||||
|
const run_benchmark = (label) => {
|
||||||
|
return new Promise((fulfil, reject) => {
|
||||||
|
const child = fork(filename, [], {
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
BENCH_SINGLE: label
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @type {{ time: number, gc_time: number } | null} */
|
||||||
|
let result = null;
|
||||||
|
|
||||||
|
child.on('message', (message) => {
|
||||||
|
result = /** @type {{ time: number, gc_time: number }} */ (message);
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('error', reject);
|
||||||
|
|
||||||
|
child.on('exit', (code) => {
|
||||||
|
if (result === null) {
|
||||||
|
reject(new Error(`benchmark ${label} exited with code ${code}`));
|
||||||
|
} else {
|
||||||
|
fulfil(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const COLUMN_WIDTHS = [25, 9, 9];
|
||||||
|
const TOTAL_WIDTH = COLUMN_WIDTHS.reduce((a, b) => a + b);
|
||||||
|
|
||||||
|
/** @type {(str: string, n: number) => string} */
|
||||||
|
const pad_right = (str, n) => str + ' '.repeat(n - str.length);
|
||||||
|
/** @type {(str: string, n: number) => string} */
|
||||||
|
const pad_left = (str, n) => ' '.repeat(n - str.length) + str;
|
||||||
|
|
||||||
|
let total_time = 0;
|
||||||
|
let total_gc_time = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const { benchmarks, name } of suites) {
|
||||||
|
let suite_time = 0;
|
||||||
|
let suite_gc_time = 0;
|
||||||
|
|
||||||
|
console.log(`\nRunning ${name}...\n`);
|
||||||
|
console.log(
|
||||||
|
pad_right('Benchmark', COLUMN_WIDTHS[0]) +
|
||||||
|
pad_left('Time', COLUMN_WIDTHS[1]) +
|
||||||
|
pad_left('GC time', COLUMN_WIDTHS[2])
|
||||||
|
);
|
||||||
|
console.log('='.repeat(TOTAL_WIDTH));
|
||||||
|
|
||||||
|
for (const benchmark of benchmarks) {
|
||||||
|
const results = await run_benchmark(benchmark.label);
|
||||||
|
console.log(
|
||||||
|
pad_right(benchmark.label, COLUMN_WIDTHS[0]) +
|
||||||
|
pad_left(results.time.toFixed(2), COLUMN_WIDTHS[1]) +
|
||||||
|
pad_left(results.gc_time.toFixed(2), COLUMN_WIDTHS[2])
|
||||||
|
);
|
||||||
|
total_time += results.time;
|
||||||
|
total_gc_time += results.gc_time;
|
||||||
|
suite_time += results.time;
|
||||||
|
suite_gc_time += results.gc_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('='.repeat(TOTAL_WIDTH));
|
||||||
console.log(
|
console.log(
|
||||||
pad_right(benchmark.label, COLUMN_WIDTHS[0]) +
|
pad_right('suite', COLUMN_WIDTHS[0]) +
|
||||||
pad_left(results.time.toFixed(2), COLUMN_WIDTHS[1]) +
|
pad_left(suite_time.toFixed(2), COLUMN_WIDTHS[1]) +
|
||||||
pad_left(results.gc_time.toFixed(2), COLUMN_WIDTHS[2])
|
pad_left(suite_gc_time.toFixed(2), COLUMN_WIDTHS[2])
|
||||||
);
|
);
|
||||||
total_time += results.time;
|
console.log('='.repeat(TOTAL_WIDTH));
|
||||||
total_gc_time += results.gc_time;
|
|
||||||
suite_time += results.time;
|
|
||||||
suite_gc_time += results.gc_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('='.repeat(TOTAL_WIDTH));
|
|
||||||
console.log(
|
|
||||||
pad_right('suite', COLUMN_WIDTHS[0]) +
|
|
||||||
pad_left(suite_time.toFixed(2), COLUMN_WIDTHS[1]) +
|
|
||||||
pad_left(suite_gc_time.toFixed(2), COLUMN_WIDTHS[2])
|
|
||||||
);
|
|
||||||
console.log('='.repeat(TOTAL_WIDTH));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PROFILE_DIR !== null) {
|
|
||||||
console.log(`\nCPU profiles written to ${PROFILE_DIR}`);
|
console.log(`\nCPU profiles written to ${PROFILE_DIR}`);
|
||||||
|
} catch (e) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(e);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$.pop();
|
console.log('');
|
||||||
|
|
||||||
console.log('');
|
console.log(
|
||||||
|
pad_right('total', COLUMN_WIDTHS[0]) +
|
||||||
console.log(
|
pad_left(total_time.toFixed(2), COLUMN_WIDTHS[1]) +
|
||||||
pad_right('total', COLUMN_WIDTHS[0]) +
|
pad_left(total_gc_time.toFixed(2), COLUMN_WIDTHS[2])
|
||||||
pad_left(total_time.toFixed(2), COLUMN_WIDTHS[1]) +
|
);
|
||||||
pad_left(total_gc_time.toFixed(2), COLUMN_WIDTHS[2])
|
}
|
||||||
);
|
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
/** @param {number} cc */
|
||||||
|
export function is_whitespace(cc) {
|
||||||
|
// fast path for common whitespace
|
||||||
|
if (cc === 32 || (cc <= 13 && cc >= 9)) return true;
|
||||||
|
// rare whitespace — \u00a0, \u1680, \u2000-\u200a, \u2028, \u2029, \u202f, \u205f, \u3000, \ufeff
|
||||||
|
if (cc < 160) return false;
|
||||||
|
return (
|
||||||
|
cc === 160 ||
|
||||||
|
cc === 5760 ||
|
||||||
|
(cc >= 8192 && cc <= 8202) ||
|
||||||
|
cc === 8232 ||
|
||||||
|
cc === 8233 ||
|
||||||
|
cc === 8239 ||
|
||||||
|
cc === 8287 ||
|
||||||
|
cc === 12288 ||
|
||||||
|
cc === 65279
|
||||||
|
);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue