summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/fifty-icons-smash.md5
-rw-r--r--packages/astro/src/runtime/server/render/common.ts37
-rw-r--r--packages/astro/test/benchmark/simple/astro.config.mjs7
-rw-r--r--packages/astro/test/benchmark/simple/package.json11
-rw-r--r--packages/astro/test/benchmark/simple/server.mjs19
-rw-r--r--packages/astro/test/benchmark/simple/src/components/Layout.astro8
-rw-r--r--packages/astro/test/benchmark/simple/src/pages/index.astro9
-rw-r--r--pnpm-lock.yaml8
8 files changed, 73 insertions, 31 deletions
diff --git a/.changeset/fifty-icons-smash.md b/.changeset/fifty-icons-smash.md
new file mode 100644
index 000000000..29dcc6354
--- /dev/null
+++ b/.changeset/fifty-icons-smash.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix perf regression in SSR
diff --git a/packages/astro/src/runtime/server/render/common.ts b/packages/astro/src/runtime/server/render/common.ts
index e64a18189..421546a46 100644
--- a/packages/astro/src/runtime/server/render/common.ts
+++ b/packages/astro/src/runtime/server/render/common.ts
@@ -45,35 +45,22 @@ export function stringifyChunk(result: SSRResult, chunk: string | RenderInstruct
}
export class HTMLParts {
- public parts: Array<HTMLBytes | string>;
+ public parts: string;
constructor() {
- this.parts = [];
+ this.parts = ''
}
append(part: string | HTMLBytes | RenderInstruction, result: SSRResult) {
if (ArrayBuffer.isView(part)) {
- this.parts.push(part);
+ this.parts += decoder.decode(part);
} else {
- this.parts.push(stringifyChunk(result, part));
+ this.parts += stringifyChunk(result, part);
}
}
toString() {
- let html = '';
- for (const part of this.parts) {
- if (ArrayBuffer.isView(part)) {
- html += decoder.decode(part);
- } else {
- html += part;
- }
- }
- return html;
+ return this.parts;
}
toArrayBuffer() {
- this.parts.forEach((part, i) => {
- if (!ArrayBuffer.isView(part)) {
- this.parts[i] = encoder.encode(String(part));
- }
- });
- return concatUint8Arrays(this.parts as Uint8Array[]);
+ return encoder.encode(this.parts);
}
}
@@ -86,15 +73,3 @@ export function chunkToByteArray(
}
return encoder.encode(stringifyChunk(result, chunk));
}
-
-export function concatUint8Arrays(arrays: Array<Uint8Array>) {
- let len = 0;
- arrays.forEach((arr) => (len += arr.length));
- let merged = new Uint8Array(len);
- let offset = 0;
- arrays.forEach((arr) => {
- merged.set(arr, offset);
- offset += arr.length;
- });
- return merged;
-}
diff --git a/packages/astro/test/benchmark/simple/astro.config.mjs b/packages/astro/test/benchmark/simple/astro.config.mjs
new file mode 100644
index 000000000..da503f3ba
--- /dev/null
+++ b/packages/astro/test/benchmark/simple/astro.config.mjs
@@ -0,0 +1,7 @@
+import { defineConfig } from 'astro/config';
+import nodejs from '@astrojs/node';
+
+export default defineConfig({
+ output: 'server',
+ adapter: nodejs()
+});
diff --git a/packages/astro/test/benchmark/simple/package.json b/packages/astro/test/benchmark/simple/package.json
new file mode 100644
index 000000000..d54f76f90
--- /dev/null
+++ b/packages/astro/test/benchmark/simple/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "@benchmark/simple",
+ "scripts": {
+ "start": "node server.mjs",
+ "build": "astro build"
+ },
+ "dependencies": {
+ "astro": "workspace:*",
+ "@astrojs/node": "workspace:*"
+ }
+}
diff --git a/packages/astro/test/benchmark/simple/server.mjs b/packages/astro/test/benchmark/simple/server.mjs
new file mode 100644
index 000000000..e5844d60c
--- /dev/null
+++ b/packages/astro/test/benchmark/simple/server.mjs
@@ -0,0 +1,19 @@
+import http from 'http';
+import { handler } from './dist/server/entry.mjs';
+
+const listener = (req, res) => {
+ handler(req, res, err => {
+ if(err) {
+ res.writeHead(500);
+ res.end(err.toString());
+ } else {
+ res.writeHead(404);
+ res.end('Not found');
+ }
+ });
+};
+
+const server = http.createServer(listener);
+server.listen(3002);
+// eslint-disable-next-line no-console
+console.log(`Listening at http://localhost:3002`);
diff --git a/packages/astro/test/benchmark/simple/src/components/Layout.astro b/packages/astro/test/benchmark/simple/src/components/Layout.astro
new file mode 100644
index 000000000..c8a65f26e
--- /dev/null
+++ b/packages/astro/test/benchmark/simple/src/components/Layout.astro
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>{ Astro.props.title }</title>
+ </head>
+ <body>
+ <slot />
+ </body>
+</html>
diff --git a/packages/astro/test/benchmark/simple/src/pages/index.astro b/packages/astro/test/benchmark/simple/src/pages/index.astro
new file mode 100644
index 000000000..ee287144f
--- /dev/null
+++ b/packages/astro/test/benchmark/simple/src/pages/index.astro
@@ -0,0 +1,9 @@
+---
+import Layout from '../components/Layout.astro';
+const name = 'world';
+---
+
+<Layout title={`Index page`}>
+ <h1>index page</h1>
+ <h2>Hello { name }</h2>
+</Layout>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9d1fdfcd8..0e906a047 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1055,6 +1055,14 @@ importers:
astro: link:../../..
vue: 3.2.40
+ packages/astro/test/benchmark/simple:
+ specifiers:
+ '@astrojs/node': workspace:*
+ astro: workspace:*
+ dependencies:
+ '@astrojs/node': link:../../../../integrations/node
+ astro: link:../../..
+
packages/astro/test/fixtures/0-css:
specifiers:
'@astrojs/react': workspace:*