Skip to content

Commit

Permalink
Merge branch 'main' into view-transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored Jul 11, 2023
2 parents fd5e830 + f0666b9 commit 33c7cbf
Show file tree
Hide file tree
Showing 103 changed files with 919 additions and 367 deletions.
11 changes: 0 additions & 11 deletions .changeset/brown-shrimps-hug.md

This file was deleted.

24 changes: 0 additions & 24 deletions .changeset/chilly-pants-fix.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/cool-kids-grin.md

This file was deleted.

11 changes: 0 additions & 11 deletions .changeset/good-pigs-fetch.md

This file was deleted.

20 changes: 0 additions & 20 deletions .changeset/happy-donuts-taste.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/long-geckos-battle.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/many-nails-arrive.md

This file was deleted.

20 changes: 0 additions & 20 deletions .changeset/strong-years-travel.md

This file was deleted.

5 changes: 4 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ jobs:

- name: Get bench command
id: bench-command
env:
# protects from untrusted user input and command injection
COMMENT: ${{ github.event.comment.body }}
run: |
benchcmd=$(echo "${{ github.event.comment.body }}" | grep '!bench' | awk -F ' ' '{print $2}')
benchcmd=$(echo "$COMMENT" | grep '!bench' | awk -F ' ' '{print $2}')
echo "bench=$benchcmd" >> $GITHUB_OUTPUT
shell: bash

Expand Down
15 changes: 15 additions & 0 deletions benchmark/bench/_util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import { createRequire } from 'module';

export const astroBin = createRequire(import.meta.url).resolve('astro');

/** @typedef {{ avg: number, stdev: number, max: number }} Stat */

/**
* @param {number[]} numbers
* @returns {Stat}
*/
export function calculateStat(numbers) {
const avg = numbers.reduce((a, b) => a + b, 0) / numbers.length;
const stdev = Math.sqrt(
numbers.map((x) => Math.pow(x - avg, 2)).reduce((a, b) => a + b, 0) / numbers.length
);
const max = Math.max(...numbers);
return { avg, stdev, max };
}
73 changes: 73 additions & 0 deletions benchmark/bench/cli-startup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { fileURLToPath } from 'url';
import { execaCommand } from 'execa';
import { markdownTable } from 'markdown-table';
import { astroBin, calculateStat } from './_util.js';

/** Default project to run for this benchmark if not specified */
export const defaultProject = 'render-default';

/**
* @param {URL} projectDir
* @param {URL} outputFile
*/
export async function run(projectDir, outputFile) {
const root = fileURLToPath(projectDir);

console.log('Benchmarking `astro --help`...');
const helpStat = await benchmarkCommand(`node ${astroBin} --help`, root);
console.log('Done');

console.log('Benchmarking `astro info`...');
const infoStat = await benchmarkCommand(`node ${astroBin} info`, root);
console.log('Done');

console.log('Result preview:');
console.log('='.repeat(10));
console.log(`#### CLI Startup\n\n`);
console.log(
printResult({
'astro --help': helpStat,
'astro info': infoStat,
})
);
console.log('='.repeat(10));
}

/**
* @param {string} command
* @param {string} root
* @returns {Promise<import('./_util.js').Stat>}
*/
async function benchmarkCommand(command, root) {
/** @type {number[]} */
const durations = [];

for (let i = 0; i < 10; i++) {
const start = performance.now();
await execaCommand(command, { cwd: root });
durations.push(performance.now() - start);
}

// From the 10 durations, calculate average, standard deviation, and max value
return calculateStat(durations);
}

/**
* @param {Record<string, import('./_util.js').Stat>} result
*/
function printResult(result) {
return markdownTable(
[
['Command', 'Avg (ms)', 'Stdev (ms)', 'Max (ms)'],
...Object.entries(result).map(([command, { avg, stdev, max }]) => [
command,
avg.toFixed(2),
stdev.toFixed(2),
max.toFixed(2),
]),
],
{
align: ['l', 'r', 'r', 'r'],
}
);
}
14 changes: 4 additions & 10 deletions benchmark/bench/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { execaCommand } from 'execa';
import { waitUntilBusy } from 'port-authority';
import { markdownTable } from 'markdown-table';
import { renderFiles } from '../make-project/render-default.js';
import { calculateStat } from '../make-project/_util.js';
import { astroBin } from './_util.js';

const port = 4322;

export const defaultProject = 'render-default';

/** @typedef {{ avg: number, stdev: number, max: number }} Stat */

/**
* @param {URL} projectDir
* @param {URL} outputFile
Expand Down Expand Up @@ -68,22 +67,17 @@ async function benchmarkRenderTime() {
result[pathname].push(renderTime);
}
}
/** @type {Record<string, Stat>} */
/** @type {Record<string, import('./_util.js').Stat>} */
const processedResult = {};
for (const [pathname, times] of Object.entries(result)) {
// From the 100 results, calculate average, standard deviation, and max value
const avg = times.reduce((a, b) => a + b, 0) / times.length;
const stdev = Math.sqrt(
times.map((x) => Math.pow(x - avg, 2)).reduce((a, b) => a + b, 0) / times.length
);
const max = Math.max(...times);
processedResult[pathname] = { avg, stdev, max };
processedResult[pathname] = calculateStat(times);
}
return processedResult;
}

/**
* @param {Record<string, Stat>} result
* @param {Record<string, import('./_util.js').Stat>} result
*/
function printResult(result) {
return markdownTable(
Expand Down
2 changes: 2 additions & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Command
memory Run build memory and speed test
render Run rendering speed test
server-stress Run server stress test
cli-startup Run CLI startup speed test
Options
--project <project-name> Project to use for benchmark, see benchmark/make-project/ for available names
Expand All @@ -27,6 +28,7 @@ const benchmarks = {
memory: () => import('./bench/memory.js'),
render: () => import('./bench/render.js'),
'server-stress': () => import('./bench/server-stress.js'),
'cli-startup': () => import('./bench/cli-startup.js'),
};

if (commandName && !(commandName in benchmarks)) {
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^2.7.4"
"astro": "^2.8.1"
}
}
2 changes: 1 addition & 1 deletion examples/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"@astrojs/mdx": "^0.19.7",
"@astrojs/rss": "^2.4.3",
"@astrojs/sitemap": "^1.3.3",
"astro": "^2.7.4"
"astro": "^2.8.1"
}
}
2 changes: 1 addition & 1 deletion examples/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^2.7.4"
"astro": "^2.8.1"
},
"peerDependencies": {
"astro": "^2.0.0-beta.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"astro": "astro"
},
"dependencies": {
"astro": "^2.7.4"
"astro": "^2.8.1"
},
"devDependencies": {
"@astrojs/deno": "^4.2.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-alpine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"@astrojs/alpinejs": "^0.2.2",
"@types/alpinejs": "^3.7.1",
"alpinejs": "^3.12.2",
"astro": "^2.7.4"
"astro": "^2.8.1"
}
}
2 changes: 1 addition & 1 deletion examples/framework-lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/lit": "^2.1.0",
"@webcomponents/template-shadowroot": "^0.2.1",
"astro": "^2.7.4",
"astro": "^2.8.1",
"lit": "^2.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/framework-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@astrojs/solid-js": "^2.2.0",
"@astrojs/svelte": "^3.1.0",
"@astrojs/vue": "^2.2.1",
"astro": "^2.7.4",
"astro": "^2.8.1",
"preact": "^10.15.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/preact": "^2.2.1",
"@preact/signals": "^1.1.3",
"astro": "^2.7.4",
"astro": "^2.8.1",
"preact": "^10.15.1"
}
}
2 changes: 1 addition & 1 deletion examples/framework-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@astrojs/react": "^2.2.1",
"@types/react": "^18.2.13",
"@types/react-dom": "^18.2.6",
"astro": "^2.7.4",
"astro": "^2.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/solid-js": "^2.2.0",
"astro": "^2.7.4",
"astro": "^2.8.1",
"solid-js": "^1.7.6"
}
}
2 changes: 1 addition & 1 deletion examples/framework-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/svelte": "^3.1.0",
"astro": "^2.7.4",
"astro": "^2.8.1",
"svelte": "^3.59.1"
}
}
2 changes: 1 addition & 1 deletion examples/framework-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/vue": "^2.2.1",
"astro": "^2.7.4",
"astro": "^2.8.1",
"vue": "^3.3.4"
}
}
2 changes: 1 addition & 1 deletion examples/hackernews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/node": "^5.3.0",
"astro": "^2.7.4"
"astro": "^2.8.1"
}
}
2 changes: 1 addition & 1 deletion examples/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^2.7.4"
"astro": "^2.8.1"
},
"peerDependencies": {
"astro": "^2.0.0-beta.0"
Expand Down
Loading

0 comments on commit 33c7cbf

Please sign in to comment.