mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
59 lines
13 KiB
TypeScript
59 lines
13 KiB
TypeScript
import jsc from "bun:jsc";
|
|
import { createServer, Server } from "node:http";
|
|
import { URL } from "node:url";
|
|
import zlib from "node:zlib";
|
|
|
|
const data = `<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" href="/_next/static/media/4473ecc91f70f139-s.p.woff" as="font" crossorigin="" type="font/woff"/><link rel="preload" href="/_next/static/media/463dafcda517f24f-s.p.woff" as="font" crossorigin="" type="font/woff"/><link rel="preload" as="image" href="https://nextjs.org/icons/next.svg" fetchPriority="high"/><link rel="stylesheet" href="/_next/static/css/01541ae5165648e7.css" data-precedence="next"/><link rel="preload" as="script" fetchPriority="low" href="/_next/static/chunks/webpack-6b2f098d55ba02b2.js"/><script src="/_next/static/chunks/fd9d1056-2821b0f0cabcd8bd.js" async=""></script><script src="/_next/static/chunks/23-df62406fd8df4a89.js" async=""></script><script src="/_next/static/chunks/main-app-4783e5e93b5af5d5.js" async=""></script><script src="/_next/static/chunks/173-32f9ff9bdfb525b3.js" async=""></script><script src="/_next/static/chunks/app/page-565079b1ea34376a.js" async=""></script><title>Create Next App</title><meta name="description" content="Generated by create next app"/><link rel="icon" href="/favicon.ico" type="image/x-icon" sizes="16x16"/><meta name="next-size-adjust"/><script src="/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js" noModule=""></script></head><body class="__variable_1e4310 __variable_c3aa02 antialiased"><div class="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]"><main class="flex flex-col gap-8 row-start-2 items-center sm:items-start"><img alt="Next.js logo" fetchPriority="high" width="180" height="38" decoding="async" data-nimg="1" class="dark:invert" style="color:transparent" src="https://nextjs.org/icons/next.svg"/><ol class="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]"><li class="mb-2">Get started by editing<!-- --> <code class="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">app/page.tsx</code>.</li><li>Save and see your changes instantly.</li></ol><div class="flex gap-4 items-center flex-col sm:flex-row"><a class="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5" href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" target="_blank" rel="noopener noreferrer"><img alt="Vercel logomark" loading="lazy" width="20" height="20" decoding="async" data-nimg="1" class="dark:invert" style="color:transparent" src="https://nextjs.org/icons/vercel.svg"/>Deploy now</a><a class="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44" href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" target="_blank" rel="noopener noreferrer">Read our docs</a></div></main><footer class="row-start-3 flex gap-6 flex-wrap items-center justify-center"><a class="flex items-center gap-2 hover:underline hover:underline-offset-4" href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" target="_blank" rel="noopener noreferrer"><img aria-hidden="true" alt="File icon" loading="lazy" width="16" height="16" decoding="async" data-nimg="1" style="color:transparent" src="https://nextjs.org/icons/file.svg"/>Learn</a><a class="flex items-center gap-2 hover:underline hover:underline-offset-4" href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" target="_blank" rel="noopener noreferrer"><img aria-hidden="true" alt="Window icon" loading="lazy" width="16" height="16" decoding="async" data-nimg="1" style="color:transparent" src="https://nextjs.org/icons/window.svg"/>Examples</a><a class="flex items-center gap-2 hover:underline hover:underline-offset-4" href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" target="_blank" rel="noopener noreferrer"><img aria-hidden="true" alt="Globe icon" loading="lazy" width="16" height="16" decoding="async" data-nimg="1" style="color:transparent" src="https://nextjs.org/icons/globe.svg"/>Go to nextjs.org →</a></footer></div><script src="/_next/static/chunks/webpack-6b2f098d55ba02b2.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])</script><script>self.__next_f.push([1,"1:HL[\"/_next/static/media/4473ecc91f70f139-s.p.woff\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff\"}]\n2:HL[\"/_next/static/media/463dafcda517f24f-s.p.woff\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff\"}]\n3:HL[\"/_next/static/css/01541ae5165648e7.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"4:I[5751,[],\"\"]\n6:I[8173,[\"173\",\"static/chunks/173-32f9ff9bdfb525b3.js\",\"931\",\"static/chunks/app/page-565079b1ea34376a.js\"],\"Image\"]\n7:I[9275,[],\"\"]\n8:I[1343,[],\"\"]\na:I[6130,[],\"\"]\nb:[]\n"])</script><script>self.__next_f.push([1,"0:[\"$\",\"$L4\",null,{\"buildId\":\"Ox0kIiZiqaqrQTw92fv8T\",\"assetPrefix\":\"\",\"urlParts\":[\"\",\"\"],\"initialTree\":[\"\",{\"children\":[\"__PAGE__\",{}]},\"$undefined\",\"$undefined\",true],\"initialSeedData\":[\"\",{\"children\":[\"__PAGE__\",{},[[\"$L5\",[\"$\",\"div\",null,{\"className\":\"grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]\",\"children\":[[\"$\",\"main\",null,{\"className\":\"flex flex-col gap-8 row-start-2 items-center sm:items-start\",\"children\":[[\"$\",\"$L6\",null,{\"className\":\"dark:invert\",\"src\":\"https://nextjs.org/icons/next.svg\",\"alt\":\"Next.js logo\",\"width\":180,\"height\":38,\"priority\":true}],[\"$\",\"ol\",null,{\"className\":\"list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]\",\"children\":[[\"$\",\"li\",null,{\"className\":\"mb-2\",\"children\":[\"Get started by editing\",\" \",[\"$\",\"code\",null,{\"className\":\"bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold\",\"children\":\"app/page.tsx\"}],\".\"]}],[\"$\",\"li\",null,{\"children\":\"Save and see your changes instantly.\"}]]}],[\"$\",\"div\",null,{\"className\":\"flex gap-4 items-center flex-col sm:flex-row\",\"children\":[[\"$\",\"a\",null,{\"className\":\"rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5\",\"href\":\"https://vercel.com/new?utm_source=create-next-app\u0026utm_medium=appdir-template-tw\u0026utm_campaign=create-next-app\",\"target\":\"_blank\",\"rel\":\"noopener noreferrer\",\"children\":[[\"$\",\"$L6\",null,{\"className\":\"dark:invert\",\"src\":\"https://nextjs.org/icons/vercel.svg\",\"alt\":\"Vercel logomark\",\"width\":20,\"height\":20}],\"Deploy now\"]}],[\"$\",\"a\",null,{\"className\":\"rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44\",\"href\":\"https://nextjs.org/docs?utm_source=create-next-app\u0026utm_medium=appdir-template-tw\u0026utm_campaign=create-next-app\",\"target\":\"_blank\",\"rel\":\"noopener noreferrer\",\"children\":\"Read our docs\"}]]}]]}],[\"$\",\"footer\",null,{\"className\":\"row-start-3 flex gap-6 flex-wrap items-center justify-center\",\"children\":[[\"$\",\"a\",null,{\"className\":\"flex items-center gap-2 hover:underline hover:underline-offset-4\",\"href\":\"https://nextjs.org/learn?utm_source=create-next-app\u0026utm_medium=appdir-template-tw\u0026utm_campaign=create-next-app\",\"target\":\"_blank\",\"rel\":\"noopener noreferrer\",\"children\":[[\"$\",\"$L6\",null,{\"aria-hidden\":true,\"src\":\"https://nextjs.org/icons/file.svg\",\"alt\":\"File icon\",\"width\":16,\"height\":16}],\"Learn\"]}],[\"$\",\"a\",null,{\"className\":\"flex items-center gap-2 hover:underline hover:underline-offset-4\",\"href\":\"https://vercel.com/templates?framework=next.js\u0026utm_source=create-next-app\u0026utm_medium=appdir-template-tw\u0026utm_campaign=create-next-app\",\"target\":\"_blank\",\"rel\":\"noopener noreferrer\",\"children\":[[\"$\",\"$L6\",null,{\"aria-hidden\":true,\"src\":\"https://nextjs.org/icons/window.svg\",\"alt\":\"Window icon\",\"width\":16,\"height\":16}],\"Examples\"]}],[\"$\",\"a\",null,{\"className\":\"flex items-center gap-2 hover:underline hover:underline-offset-4\",\"href\":\"https://nextjs.org?utm_source=create-next-app\u0026utm_medium=appdir-template-tw\u0026utm_campaign=create-next-app\",\"target\":\"_blank\",\"rel\":\"noopener noreferrer\",\"children\":[[\"$\",\"$L6\",null,{\"aria-hidden\":true,\"src\":\"https://nextjs.org/icons/globe.svg\",\"alt\":\"Globe icon\",\"width\":16,\"height\":16}],\"Go to nextjs.org →\"]}]]}]]}],null],null],null]},[[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/css/01541ae5165648e7.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"children\":[\"$\",\"body\",null,{\"className\":\"__variable_1e4310 __variable_c3aa02 antialiased\",\"children\":[\"$\",\"$L7\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L8\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"padding\":\"0 23px 0 0\",\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\",\"lineHeight\":\"49px\"},\"children\":\"404\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"49px\",\"margin\":0},\"children\":\"This page could not be found.\"}]}]]}]}]],\"notFoundStyles\":[]}]}]}]],null],null],\"couldBeIntercepted\":false,\"initialHead\":[null,\"$L9\"],\"globalErrorComponent\":\"$a\",\"missingSlots\":\"$Wb\"}]\n"])</script><script>self.__next_f.push([1,"9:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}],[\"$\",\"meta\",\"1\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"2\",{\"children\":\"Create Next App\"}],[\"$\",\"meta\",\"3\",{\"name\":\"description\",\"content\":\"Generated by create next app\"}],[\"$\",\"link\",\"4\",{\"rel\":\"icon\",\"href\":\"/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"16x16\"}],[\"$\",\"meta\",\"5\",{\"name\":\"next-size-adjust\"}]]\n5:null\n"])</script></body></html>`;
|
|
|
|
function listen(server: Server, protocol: string = "http"): Promise<URL> {
|
|
return new Promise((resolve, reject) => {
|
|
const timeout = setTimeout(() => reject("Timed out"), 5000).unref();
|
|
server.listen({ port: 0 }, (err, hostname, port) => {
|
|
clearTimeout(timeout);
|
|
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(new URL(`${protocol}://${hostname}:${port}`));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
const baseline = process.memoryUsage.rss();
|
|
let count = 0;
|
|
|
|
var server = createServer(async (req, res) => {
|
|
res.writeHead(200, { "Content-Type": "application/gzip" });
|
|
const gz = zlib.createGzip();
|
|
|
|
gz.pipe(res);
|
|
|
|
for (let i = 0; i < 10; i++) gz.write(data);
|
|
await Bun.sleep(10);
|
|
for (let i = 0; i < 10; i++) gz.write(data);
|
|
await Bun.sleep(10);
|
|
for (let i = 0; i < 10; i++) gz.write(data);
|
|
for (let i = 0; i < 10; i++) gz.write(data);
|
|
await Bun.sleep(10);
|
|
for (let i = 0; i < 10; i++) gz.write(data);
|
|
for (let i = 0; i < 10; i++) gz.write(data);
|
|
for (let i = 0; i < 10; i++) gz.write(data);
|
|
gz.end();
|
|
|
|
count += 1;
|
|
if (count % 1000 === 0) {
|
|
Bun.gc(true);
|
|
console.log("count", count, process.memoryUsage.rss());
|
|
}
|
|
if (count == 10_000) {
|
|
Bun.gc(true);
|
|
const after = process.memoryUsage.rss();
|
|
console.log("heapStats", jsc.heapStats());
|
|
process.send({ baseline, after });
|
|
}
|
|
});
|
|
const url = await listen(server);
|
|
console.log("server", "listening on", url.port);
|
|
process.send(url.port);
|