Skip to content
New issue

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

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

Already on GitHub? # to your account

fix benchmark script #66789

Merged
merged 3 commits into from
Jun 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Comp from '../../components/index.jsx'
export default function Home() {
return (
<>
<h1>Hello!!!!!!!!!!!!</h1>
<h1>Hello!</h1>
<Comp />
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ import React from 'react'
import Comp from '../../components/index.jsx'

export default function Home() {
return <Comp />
return (
<>
<h1>Hello!</h1>
<Comp />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ClientComponent from './client-component'
export default function Home() {
return (
<>
<h1>Hello!</h1>
<Comp />
<ClientComponent />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ import React from 'react'
import Comp from '../../components/index.jsx'

export default function Home() {
return <Comp />
return (
<>
<h1>Hello!</h1>
<Comp />
</>
)
}
145 changes: 78 additions & 67 deletions bench/nested-deps-app-router/bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import prettyMs from 'pretty-ms'
import treeKill from 'tree-kill'

const ROOT_DIR = join(fileURLToPath(import.meta.url), '..', '..', '..')
const CWD = join(ROOT_DIR, 'bench', 'nested-deps')
const CWD = join(ROOT_DIR, 'bench', 'nested-deps-app-router')

const NEXT_BIN = join(ROOT_DIR, 'packages', 'next', 'dist', 'bin', 'next')

Expand Down Expand Up @@ -115,7 +115,7 @@ function runNextCommandDev(argv, opts = {}) {
function handleStdout(data) {
const message = data.toString()
const bootupMarkers = {
dev: /compiled .*successfully/i,
dev: /Ready in .*/i,
start: /started server/i,
}
if (
Expand Down Expand Up @@ -171,83 +171,94 @@ function waitFor(millis) {
return new Promise((resolve) => setTimeout(resolve, millis))
}

await fs.rm('.next', { recursive: true }).catch(() => {})
const file = new File(join(CWD, 'pages/index.jsx'))
const results = []

try {
if (command === 'dev' || command === 'all') {
const instance = await runNextCommandDev(['dev', '--port', '3000'])

function waitForCompiled() {
return new Promise((resolve) => {
function waitForOnData(data) {
const message = data.toString()
const compiledRegex =
/compiled client and server successfully in (\d*[.]?\d+)\s*(m?s) \((\d+) modules\)/gm
const matched = compiledRegex.exec(message)
if (matched) {
resolve({
'time (ms)': (matched[2] === 's' ? 1000 : 1) * Number(matched[1]),
modules: Number(matched[3]),
})
instance.stdout.removeListener('data', waitForOnData)
for (const testCase of [
'client-components-only',
'server-and-client-components',
'server-components-only',
]) {
await fs.rm('.next', { recursive: true }).catch(() => {})
const file = new File(join(CWD, `app/${testCase}/page.js`))
const results = []

try {
if (command === 'dev' || command === 'all') {
const instance = await runNextCommandDev(['dev', '--port', '3000'])

function waitForCompiled() {
return new Promise((resolve) => {
function waitForOnData(data) {
const message = data.toString()
const compiledRegex =
/Compiled (?:.+ )?in (\d*[.]?\d+)\s*(m?s)(?: \((\d+) modules\))?/gm
const matched = compiledRegex.exec(message)
if (matched) {
resolve({
'time (ms)':
(matched[2] === 's' ? 1000 : 1) * Number(matched[1]),
modules: Number(matched[3]),
})
instance.stdout.removeListener('data', waitForOnData)
}
}
}
instance.stdout.on('data', waitForOnData)
})
}
instance.stdout.on('data', waitForOnData)
})
}

const [res, initial] = await Promise.all([
fetch('http://localhost:3000/'),
waitForCompiled(),
])
if (res.status !== 200) {
throw new Error('Fetching / failed')
}
const [res, initial] = await Promise.all([
fetch(`http://localhost:3000/${testCase}`),
waitForCompiled(),
])
if (res.status !== 200) {
throw new Error(`Fetching /${testCase} failed`)
}

results.push(initial)
results.push(initial)

file.prepend('// First edit')
await waitFor(1000)

results.push(await waitForCompiled())
file.replace('Hello', 'Hello!')

await waitFor(1000)
results.push(await waitForCompiled())

file.prepend('// Second edit')
await waitFor(1000)

results.push(await waitForCompiled())
file.replace('Hello', 'Hello!')

await waitFor(1000)
results.push(await waitForCompiled())

file.prepend('// Third edit')
await waitFor(1000)

results.push(await waitForCompiled())
file.replace('Hello', 'Hello!')

console.table(results)
results.push(await waitForCompiled())

await killApp(instance)
}
if (command === 'build' || command === 'all') {
// ignore error
await fs.rm('.next', { recursive: true, force: true }).catch(() => {})

execSync(`node ${NEXT_BIN} build ./bench/nested-deps`, {
cwd: ROOT_DIR,
stdio: 'inherit',
env: {
...process.env,
TRACE_TARGET: 'jaeger',
},
})
const traceString = await fs.readFile(join(CWD, '.next', 'trace'), 'utf8')
const traces = traceString
.split('\n')
.filter((line) => line)
.map((line) => JSON.parse(line))
const { duration } = traces.pop().find(({ name }) => name === 'next-build')
console.info('next build duration: ', prettyMs(duration / 1000))
console.table(results)

await killApp(instance)
}
if (command === 'build' || command === 'all') {
// ignore error
await fs.rm('.next', { recursive: true, force: true }).catch(() => {})

execSync(`node ${NEXT_BIN} build ./bench/nested-deps-app-router`, {
cwd: ROOT_DIR,
stdio: 'inherit',
env: {
...process.env,
TRACE_TARGET: 'jaeger',
},
})
const traceString = await fs.readFile(join(CWD, '.next', 'trace'), 'utf8')
const traces = traceString
.split('\n')
.filter((line) => line)
.map((line) => JSON.parse(line))
const { duration } = traces
.pop()
.find(({ name }) => name === 'next-build')
console.info('next build duration: ', prettyMs(duration / 1000))
}
} finally {
file.restore()
}
} finally {
file.restore()
}
10 changes: 5 additions & 5 deletions bench/nested-deps/bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function runNextCommandDev(argv, opts = {}) {
function handleStdout(data) {
const message = data.toString()
const bootupMarkers = {
dev: /compiled .*successfully/i,
dev: /Ready in .*/i,
start: /started server/i,
}
if (
Expand Down Expand Up @@ -184,7 +184,7 @@ try {
function waitForOnData(data) {
const message = data.toString()
const compiledRegex =
/compiled client and server successfully in (\d*[.]?\d+)\s*(m?s) \((\d+) modules\)/gm
/Compiled (?:.+ )?in (\d*[.]?\d+)\s*(m?s)(?: \((\d+) modules\))?/gm
const matched = compiledRegex.exec(message)
if (matched) {
resolve({
Expand All @@ -208,19 +208,19 @@ try {

results.push(initial)

file.prepend('// First edit')
file.replace('Hello', 'Hello!')

results.push(await waitForCompiled())

await waitFor(1000)

file.prepend('// Second edit')
file.replace('Hello', 'Hello!')

results.push(await waitForCompiled())

await waitFor(1000)

file.prepend('// Third edit')
file.replace('Hello', 'Hello!')

results.push(await waitForCompiled())

Expand Down
7 changes: 6 additions & 1 deletion bench/nested-deps/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Comp from '../components/index.jsx'

export default function Home() {
return <Comp />
return (
<>
<h1>Hello!</h1>
<Comp />
</>
)
}