Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce amount of data passed to collectBuildTraces #59665

Merged
merged 7 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions packages/next/src/build/collect-build-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import {

import path from 'path'
import fs from 'fs/promises'
import {
deserializePageInfos,
type PageInfos,
type SerializedPageInfos,
} from './utils'
import { loadBindings } from './swc'
import { nonNullable } from '../lib/non-nullable'
import * as ciEnvironment from '../telemetry/ci-info'
Expand All @@ -30,6 +25,7 @@ import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import isError from '../lib/is-error'
import type { NodeFileTraceReasons } from '@vercel/nft'
import type { RoutesUsingEdgeRuntime } from './utils'

const debug = debugOriginal('next:build:build-traces')

Expand Down Expand Up @@ -86,7 +82,7 @@ export async function collectBuildTraces({
dir,
config,
distDir,
pageInfos,
edgeRuntimeRoutes,
staticPages,
nextBuildSpan = new Span({ name: 'build' }),
hasSsrAmpPages,
Expand All @@ -99,7 +95,7 @@ export async function collectBuildTraces({
hasSsrAmpPages: boolean
outputFileTracingRoot: string
// pageInfos is serialized when this function runs in a worker.
pageInfos: PageInfos | SerializedPageInfos
edgeRuntimeRoutes: RoutesUsingEdgeRuntime
nextBuildSpan?: Span
config: NextConfigComplete
buildTraceContext?: BuildTraceContext
Expand Down Expand Up @@ -673,8 +669,6 @@ export async function collectBuildTraces({
}

const { entryNameFilesMap } = buildTraceContext?.chunksTrace || {}
const infos =
pageInfos instanceof Map ? pageInfos : deserializePageInfos(pageInfos)

await Promise.all(
[
Expand All @@ -695,8 +689,7 @@ export async function collectBuildTraces({
}

// edge routes have no trace files
const pageInfo = infos.get(route)
if (pageInfo?.runtime === 'edge') {
if (edgeRuntimeRoutes.hasOwnProperty(route)) {
return
}

Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import {
copyTracedFiles,
isReservedPage,
isAppBuiltinNotFoundPage,
serializePageInfos,
collectRoutesUsingEdgeRuntime,
} from './utils'
import type { PageInfo, PageInfos, AppConfig } from './utils'
import { writeBuildId } from './write-build-id'
Expand Down Expand Up @@ -1650,7 +1650,7 @@ export default async function build(
config,
distDir,
// Serialize Map as this is sent to the worker.
pageInfos: serializePageInfos(new Map()),
edgeRuntimeRoutes: collectRoutesUsingEdgeRuntime(new Map()),
staticPages: [],
hasSsrAmpPages: false,
buildTraceContext,
Expand Down Expand Up @@ -2387,7 +2387,7 @@ export default async function build(
dir,
config,
distDir,
pageInfos,
edgeRuntimeRoutes: collectRoutesUsingEdgeRuntime(pageInfos),
staticPages: [...staticPages],
nextBuildSpan,
hasSsrAmpPages,
Expand Down
19 changes: 13 additions & 6 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,21 @@ export interface PageInfo {

export type PageInfos = Map<string, PageInfo>

export type SerializedPageInfos = [string, PageInfo][]

export function serializePageInfos(input: PageInfos): SerializedPageInfos {
return Array.from(input.entries())
export interface RoutesUsingEdgeRuntime {
[route: string]: 0
}

export function deserializePageInfos(input: SerializedPageInfos): PageInfos {
return new Map(input)
export function collectRoutesUsingEdgeRuntime(
input: PageInfos
): RoutesUsingEdgeRuntime {
const routesUsingEdgeRuntime: RoutesUsingEdgeRuntime = {}
for (const [route, info] of input.entries()) {
if (isEdgeRuntime(info.runtime)) {
routesUsingEdgeRuntime[route] = 0
}
}

return routesUsingEdgeRuntime
}

export async function printTreeView(
Expand Down