summaryrefslogtreecommitdiff
path: root/benchmark/packages
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2024-11-06 12:33:14 +0000
committerGravatar GitHub <noreply@github.com> 2024-11-06 12:33:14 +0000
commited5a9f1b755f9ae31735dacf75b970669c8c38c8 (patch)
treeb539b47c4bbf6bfac981b5d65ff3a92c4339d09b /benchmark/packages
parent222f71894cc7118319ce83b3b29fa61a9dbebb75 (diff)
downloadastro-ed5a9f1b755f9ae31735dacf75b970669c8c38c8.tar.gz
astro-ed5a9f1b755f9ae31735dacf75b970669c8c38c8.tar.zst
astro-ed5a9f1b755f9ae31735dacf75b970669c8c38c8.zip
chore: codspeed benchmark (#12347)
Diffstat (limited to 'benchmark/packages')
-rw-r--r--benchmark/packages/adapter/README.md3
-rw-r--r--benchmark/packages/adapter/package.json35
-rw-r--r--benchmark/packages/adapter/src/index.ts32
-rw-r--r--benchmark/packages/adapter/src/server.ts34
-rw-r--r--benchmark/packages/adapter/tsconfig.json7
-rw-r--r--benchmark/packages/timer/src/index.ts4
-rw-r--r--benchmark/packages/timer/src/server.ts2
7 files changed, 115 insertions, 2 deletions
diff --git a/benchmark/packages/adapter/README.md b/benchmark/packages/adapter/README.md
new file mode 100644
index 000000000..5b8e33ed4
--- /dev/null
+++ b/benchmark/packages/adapter/README.md
@@ -0,0 +1,3 @@
+# @benchmark/timer
+
+Like `@astrojs/node`, but returns the rendered time in milliseconds for the page instead of the page content itself. This is used for internal benchmarks only.
diff --git a/benchmark/packages/adapter/package.json b/benchmark/packages/adapter/package.json
new file mode 100644
index 000000000..2bdb73ce9
--- /dev/null
+++ b/benchmark/packages/adapter/package.json
@@ -0,0 +1,35 @@
+{
+ "name": "@benchmark/adapter",
+ "description": "Bench adapter",
+ "private": true,
+ "version": "0.0.0",
+ "type": "module",
+ "types": "./dist/index.d.ts",
+ "author": "withastro",
+ "license": "MIT",
+ "keywords": [
+ "withastro",
+ "astro-adapter"
+ ],
+ "exports": {
+ ".": "./dist/index.js",
+ "./server.js": "./dist/server.js",
+ "./package.json": "./package.json"
+ },
+ "scripts": {
+ "build": "astro-scripts build \"src/**/*.ts\" && tsc",
+ "build:ci": "astro-scripts build \"src/**/*.ts\"",
+ "dev": "astro-scripts dev \"src/**/*.ts\""
+ },
+ "dependencies": {
+ "server-destroy": "^1.0.1"
+ },
+ "peerDependencies": {
+ "astro": "workspace:*"
+ },
+ "devDependencies": {
+ "@types/server-destroy": "^1.0.4",
+ "astro": "workspace:*",
+ "astro-scripts": "workspace:*"
+ }
+}
diff --git a/benchmark/packages/adapter/src/index.ts b/benchmark/packages/adapter/src/index.ts
new file mode 100644
index 000000000..f2345deb0
--- /dev/null
+++ b/benchmark/packages/adapter/src/index.ts
@@ -0,0 +1,32 @@
+import type { AstroAdapter, AstroIntegration } from 'astro';
+
+export default function createIntegration(): AstroIntegration {
+ return {
+ name: '@benchmark/timer',
+ hooks: {
+ 'astro:config:setup': ({ updateConfig }) => {
+ updateConfig({
+ vite: {
+ ssr: {
+ noExternal: ['@benchmark/timer'],
+ },
+ },
+ });
+ },
+ 'astro:config:done': ({ setAdapter }) => {
+ setAdapter({
+ name: '@benchmark/adapter',
+ serverEntrypoint: '@benchmark/adapter/server.js',
+ exports: ['manifest', 'createApp'],
+ supportedAstroFeatures: {
+ serverOutput: 'stable',
+ envGetSecret: 'experimental',
+ staticOutput: 'stable',
+ hybridOutput: 'stable',
+ i18nDomains: 'stable',
+ },
+ });
+ },
+ },
+ };
+}
diff --git a/benchmark/packages/adapter/src/server.ts b/benchmark/packages/adapter/src/server.ts
new file mode 100644
index 000000000..ca69fe28f
--- /dev/null
+++ b/benchmark/packages/adapter/src/server.ts
@@ -0,0 +1,34 @@
+import * as fs from 'node:fs';
+import type { SSRManifest } from 'astro';
+import { App } from 'astro/app';
+import { applyPolyfills } from 'astro/app/node';
+
+applyPolyfills();
+
+class MyApp extends App {
+ #manifest: SSRManifest | undefined;
+ #streaming: boolean;
+ constructor(manifest: SSRManifest, streaming = false) {
+ super(manifest, streaming);
+ this.#manifest = manifest;
+ this.#streaming = streaming;
+ }
+
+ async render(request: Request) {
+ const url = new URL(request.url);
+ if (this.#manifest?.assets.has(url.pathname)) {
+ const filePath = new URL('../../client/' + this.removeBase(url.pathname), import.meta.url);
+ const data = await fs.promises.readFile(filePath);
+ return new Response(data);
+ }
+
+ return super.render(request);
+ }
+}
+
+export function createExports(manifest: SSRManifest) {
+ return {
+ manifest,
+ createApp: (streaming: boolean) => new MyApp(manifest, streaming),
+ };
+}
diff --git a/benchmark/packages/adapter/tsconfig.json b/benchmark/packages/adapter/tsconfig.json
new file mode 100644
index 000000000..1504b4b6d
--- /dev/null
+++ b/benchmark/packages/adapter/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "extends": "../../../tsconfig.base.json",
+ "include": ["src"],
+ "compilerOptions": {
+ "outDir": "./dist"
+ }
+}
diff --git a/benchmark/packages/timer/src/index.ts b/benchmark/packages/timer/src/index.ts
index 1c54e3727..f83a61c36 100644
--- a/benchmark/packages/timer/src/index.ts
+++ b/benchmark/packages/timer/src/index.ts
@@ -6,7 +6,9 @@ export function getAdapter(): AstroAdapter {
serverEntrypoint: '@benchmark/timer/server.js',
previewEntrypoint: '@benchmark/timer/preview.js',
exports: ['handler'],
- supportedAstroFeatures: {},
+ supportedAstroFeatures: {
+ serverOutput: 'stable',
+ },
};
}
diff --git a/benchmark/packages/timer/src/server.ts b/benchmark/packages/timer/src/server.ts
index 9905a627b..edcfaa248 100644
--- a/benchmark/packages/timer/src/server.ts
+++ b/benchmark/packages/timer/src/server.ts
@@ -13,6 +13,6 @@ export function createExports(manifest: SSRManifest) {
const end = performance.now();
res.write(end - start + '');
res.end();
- },
+ }
};
}