Skip to content

Commit ff9b1ed

Browse files
committed
feat: queued rendering
1 parent 495148c commit ff9b1ed

File tree

36 files changed

+2019
-1
lines changed

36 files changed

+2019
-1
lines changed

.github/workflows/continuous_benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
strategy:
2828
matrix:
29-
shard: [ "1/4","2/4", "3/4", "4/4" ]
29+
shard: [ "1/6", "2/6", "3/6", "4/6", "5/6", "6/6" ]
3030
permissions:
3131
contents: read
3232
pull-requests: write
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { fileURLToPath } from 'node:url';
2+
import { build } from 'astro';
3+
import { bench, describe } from 'vitest';
4+
5+
const queueBuildRoot = fileURLToPath(new URL('../static-projects/queue-build', import.meta.url));
6+
7+
describe('Bench queue-based build time', () => {
8+
bench(
9+
'Build: queue rendering static site',
10+
async () => {
11+
await build({
12+
root: queueBuildRoot,
13+
logLevel: 'error',
14+
});
15+
},
16+
{ timeout: 300000, iterations: 3 },
17+
);
18+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { existsSync } from 'node:fs';
2+
import { fileURLToPath } from 'node:url';
3+
import { beforeAll, bench, describe } from 'vitest';
4+
5+
const queueRenderRoot = new URL('../projects/queue-render-bench/', import.meta.url);
6+
7+
let app;
8+
beforeAll(async () => {
9+
const entry = new URL('./dist/server/entry.mjs', queueRenderRoot);
10+
11+
if (!existsSync(fileURLToPath(entry))) {
12+
throw new Error(
13+
'queue-render-bench project not built. Please run `pnpm run build:bench` before running the benchmarks.',
14+
);
15+
}
16+
17+
const { manifest, createApp } = await import(entry);
18+
app = createApp(manifest, false);
19+
}, 900000);
20+
21+
describe('Bench queue-based rendering', () => {
22+
bench('Queue rendering: .astro file', async () => {
23+
const request = new Request(new URL('http://example.com/astro'));
24+
await app.render(request);
25+
});
26+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import fs from 'node:fs/promises';
2+
3+
// Queue rendering benchmark - tests SSR rendering performance with queue-based engine
4+
const files = {
5+
'pages/astro.astro': `\
6+
---
7+
const className = "text-red-500";
8+
const style = { color: "red" };
9+
const items = Array.from({ length: 10000 }, (_, i) => ({ i }));
10+
---
11+
<html>
12+
<head>
13+
<title>Queue Rendering Benchmark</title>
14+
</head>
15+
<body>
16+
<h1 class={className + ' text-lg'}>Queue Rendering List</h1>
17+
<ul style={style}>
18+
{items.map((item) => (
19+
<li class={className}>
20+
<a
21+
href={item.i}
22+
aria-current={item.i === 0}
23+
class:list={[{ large: item.i === 0 }, className]}
24+
>
25+
<span>{item.i}</span>
26+
</a>
27+
</li>
28+
))}
29+
</ul>
30+
</body>
31+
</html>`,
32+
};
33+
34+
/**
35+
* @param {URL} projectDir
36+
*/
37+
export async function run(projectDir) {
38+
await fs.rm(projectDir, { recursive: true, force: true });
39+
await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true });
40+
41+
await Promise.all(
42+
Object.entries(files).map(([name, content]) => {
43+
return fs.writeFile(new URL(`./src/${name}`, projectDir), content, 'utf-8');
44+
}),
45+
);
46+
47+
await fs.writeFile(
48+
new URL('./astro.config.js', projectDir),
49+
`\
50+
import { defineConfig } from 'astro/config';
51+
import adapter from '@benchmark/adapter';
52+
53+
export default defineConfig({
54+
output: 'server',
55+
adapter: adapter(),
56+
experimental: {
57+
queuedRendering: true,
58+
},
59+
});`,
60+
'utf-8',
61+
);
62+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'astro/config';
2+
3+
export default defineConfig({
4+
output: 'static',
5+
experimental: {
6+
queuedRendering: true,
7+
},
8+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "benchmark-queue-build",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"description": "Queue rendering build benchmark",
6+
"scripts": {
7+
"build": "astro build"
8+
},
9+
"dependencies": {
10+
"astro": "workspace:^"
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
const items = Array.from({ length: 10000 }, (_, i) => ({
3+
title: `Item ${i + 1}`,
4+
description: 'Queue rendering benchmark item',
5+
value: i,
6+
}));
7+
---
8+
9+
<html>
10+
<head>
11+
<title>Queue Build Benchmark</title>
12+
</head>
13+
<body>
14+
<h1>Queue Build Benchmark</h1>
15+
<section>
16+
{items.map((item) => (
17+
<div class="item">
18+
<h3>{item.title}</h3>
19+
<p>{item.description}</p>
20+
<span>Value: {item.value}</span>
21+
</div>
22+
))}
23+
</section>
24+
</body>
25+
</html>

packages/astro/src/container/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ function createManifest(
175175
placement: undefined,
176176
},
177177
logLevel: 'silent',
178+
experimentalQueuedRendering: manifest?.experimentalQueuedRendering ?? undefined,
178179
};
179180
}
180181

@@ -264,6 +265,7 @@ type AstroContainerManifest = Pick<
264265
| 'allowedDomains'
265266
| 'serverLike'
266267
| 'assetsDir'
268+
| 'experimentalQueuedRendering'
267269
>;
268270

269271
type AstroContainerConstructor = {

packages/astro/src/core/app/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export type SSRManifest = {
7272
trailingSlash: AstroConfig['trailingSlash'];
7373
buildFormat: NonNullable<AstroConfig['build']>['format'];
7474
compressHTML: boolean;
75+
experimentalQueuedRendering: boolean | undefined;
7576
assetsPrefix?: AssetsPrefix;
7677
renderers: SSRLoadedRenderer[];
7778
/**

packages/astro/src/core/build/plugins/plugin-manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ async function buildManifest(
321321
trailingSlash: settings.config.trailingSlash,
322322
compressHTML: settings.config.compressHTML,
323323
assetsPrefix: settings.config.build.assetsPrefix,
324+
experimentalQueuedRendering: settings.config.experimental?.queuedRendering,
324325
componentMetadata: Array.from(internals.componentMetadata),
325326
renderers: [],
326327
clientDirectives: Array.from(settings.clientDirectives),

0 commit comments

Comments
 (0)