Hey all, on 7th December I switched a specific route to edge (export const runtime = “edge”;)
I’m, noticing, that my active CPU increased drastically since then:
I haven’t changed anything else. The route.ts is quite simple, it returns some templated html, no external calls / APIs.
route.ts:
import { NextRequest, NextResponse } from "next/server";
export const runtime = "edge"; // this caused the increase in CPU time, no other deployment that day
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ module: string[] }> }
) {
const { module: moduleArray } = await params;
const moduleName = moduleArray.join("/");
// Safety check: ensure we have a module name
if (!moduleName) {
const redirectResponse = NextResponse.redirect("https://github.com/atomicgo", 308);
redirectResponse.headers.set(
"Cache-Control",
"public, s-maxage=31536000, stale-while-revalidate=31536000, max-age=31536000, immutable"
);
return redirectResponse;
}
const searchParams = request.nextUrl.searchParams;
const goGet = searchParams.get("go-get");
// If go-get=1 is present, return the HTML with meta tags
if (goGet === "1") {
const html = `<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="atomicgo.dev/${moduleName} git https://github.com/atomicgo/${moduleName}.git">
<meta name="go-source" content="atomicgo.dev/${moduleName} https://github.com/atomicgo/${moduleName} https://github.com/atomicgo/${moduleName}/tree/main{/dir} https://github.com/atomicgo/${moduleName}/blob/main{/dir}/{file}#L{line}">
</head>
</html>`;
return new NextResponse(html, {
headers: {
"Content-Type": "text/html; charset=utf-8",
"Cache-Control": "public, s-maxage=31536000, stale-while-revalidate=31536000, max-age=31536000, immutable",
},
});
}
// Otherwise, redirect to GitHub
const redirectResponse = NextResponse.redirect(
`https://github.com/atomicgo/${moduleName}`,
302
);
redirectResponse.headers.set(
"Cache-Control",
"public, s-maxage=31536000, stale-while-revalidate=31536000, max-age=31536000, immutable"
);
return redirectResponse;
}
(Yes I know, that code needs some refactoring)
I would be glad, if someone could explain me, why running on edge is increasing the overall active CPU time by so much.
Also, is Edge the correct runtime for this function? It has low traffic (couple thousand requests / day), but the HTML for the same parameters is completely static after first generation(could be cached forever).
In my limited knowledge about Vercel (new here), I thought edge was supposed to be faster, as it’s closer to the users. Also the runtime is smaller afaik, so I don’t understand the change in metrics.
Thanks in advance!!
More screenshots:
P95:








