rsnext/test/unit
Jimmy Lai d52d32f423
perf: improve Pages Router server rendering performance (#64461)
### What

This PR's goal is to improve the throughput performance of the Next.js
server when handling Pages Router routes.

Note that the results from this are very synthetic and do not represent
the real-life performance of an application. If we only wanted to handle
hello worlds, we could probably make this even faster but on production,
a slow fetch call to your DB is probably what's slowing you down.

I'll look into App Router next.

### Why?

I guess I got nerd-sniped into it 😃 

### How?

A few optimizations:
- I looked deeply at the pipeline for rendering a Pages Router page. I
noticed a lot of intermediary streams being created here and there to
eventually be concatenated to a simple string. I think this is probably
left over code from when we wanted to support streaming there and so
there's some code that was shared with the App Router, which we
absolutely don't need I think. I refactored it to be slightly simpler
with just a few string concats here and there.
- misc: I removed some redundant Promises being created here and there
and added a small inline optimisation to eliminate `if (renderOpts.dev)`
code in production.

### Nummies

Test setup: hello world pages router app, next start + autocannon

- requests handled in 10s: 18k  -> 33K, **~80% improvement**
- avg latency: 4.89ms -> 2.8ms, **~42% improvement**
- avg req/res: 1846.5 -> 2983.5, **~61% improvement**

Before

<img width="742" alt="image"
src="https://github.com/vercel/next.js/assets/11064311/658e7ade-eba7-4604-a7c9-619bd51a5ec8">

vs

after

<img width="880" alt="image"
src="https://github.com/vercel/next.js/assets/11064311/2f46cf69-b788-4db2-bf90-6f65dc7abd82">




<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-3103
2024-04-16 14:25:45 +02:00
..
cssnano-simple More Turbopack fixes (#56299) 2023-10-02 13:55:23 +00:00
eslint-plugin-next feat(eslint): enhance no-unwanted-polyfill w/ new endpoints (#62719) 2024-03-06 16:42:53 +00:00
esm-interpolate Make esm default interpolation work with jest mock (#36877) 2022-05-13 16:39:38 +00:00
fixtures Fix static info parsing when export data fetching method as variable (#40317) 2022-09-07 09:28:15 -07:00
image-optimizer fix:(next/image) handle remotePatterns with a dot in the pathname (#60488) 2024-02-08 18:21:29 -05:00
incremental-cache fix: revalidation with file-system-cache (#58508) 2023-11-16 23:34:50 +00:00
isolated perf: improve Pages Router server rendering performance (#64461) 2024-04-16 14:25:45 +02:00
next-image-loader fix(next/image): empty blur image when animated (#54028) 2023-08-15 02:17:40 +00:00
web-runtime chore: drop undici (#56899) 2023-10-19 18:35:12 +00:00
accept-headers.test.ts (Fix)(Tests)Fix typo in unit testing (#47644) 2023-04-01 22:23:15 -07:00
babel-plugin-next-page-config.test.ts Babel & next-swc: Fix exporting page config with AsExpression (#32702) 2022-02-05 21:15:49 +00:00
babel-plugin-next-ssg-transform.test.ts chore: update ESLint and plugins to latest (#61544) 2024-02-01 20:06:02 -05:00
create-client-router-filter.test.ts Update default error rate for client filter (#60542) 2024-01-11 17:51:53 -08:00
example.txt Add util for generating new tests/error documents (#33001) 2022-01-06 09:45:04 -06:00
find-config.test.ts Support postcss.config.cjs (#38486) 2022-07-18 14:34:29 -05:00
find-page-file.test.ts Support generate dynamic sitemaps for dynamic routes (#48867) 2023-04-26 20:41:37 +00:00
get-files-in-dir.test.ts Resolve build issues with symlinked files (#57412) 2023-12-04 11:43:13 +01:00
get-node-options-without-inspect.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
get-page-static-infos.test.ts ensure original matcher source is free of mutations (#47980) 2023-04-12 16:55:45 +02:00
get-project-dir.test.ts fix(next): dev server starting when importing a file using get-projec… (#38274) 2022-08-07 17:31:30 +00:00
getDisplayName.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
htmlescape.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
infer-get-server-side-props-type.test.ts fix: InferGetServerSidePropsType and InferGetStaticPropsType (#40635) 2022-09-20 15:25:01 -07:00
infer-get-static-props.test.ts fix: InferGetServerSidePropsType and InferGetStaticPropsType (#40635) 2022-09-20 15:25:01 -07:00
is-equal-node.unit.test.ts correctly assess node equality when nonce attribute is present (#27573) 2021-11-10 19:31:32 -06:00
is-serializable-props.test.ts chore: upgrade jest (#56909) 2023-10-19 17:38:24 +00:00
jest-next-swc.test.ts Ensure mjs files are transformed with jest (#34698) 2022-03-09 13:49:58 +01:00
link-rendering.test.ts chore: upgrade jest (#56909) 2023-10-19 17:38:24 +00:00
link-warnings.test.tsx Update repo to use react 18 by default (#35888) 2022-04-05 21:51:47 +00:00
loadGetInitialProps.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
mitt.test.ts (Fix)(Tests)Fix typo in unit testing (#47644) 2023-04-01 22:23:15 -07:00
next-babel-loader-dev.test.ts chore: upgrade jest (#56909) 2023-10-19 17:38:24 +00:00
next-babel-loader-prod.test.ts chore: upgrade jest (#56909) 2023-10-19 17:38:24 +00:00
next-babel.test.ts chore: upgrade jest (#56909) 2023-10-19 17:38:24 +00:00
next-dynamic.test.tsx Separate next/dynamic implementation for app and pages (#45565) 2023-02-04 01:45:35 +00:00
next-head-rendering.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
next-image-get-img-props.test.ts feat(next/image): add overrideSrc prop (#64221) 2024-04-09 10:48:01 -04:00
next-image-legacy.test.ts BREAKING CHANGE: Rename next/image to next/legacy/image & rename next/future/image to next/image (#41399) 2022-10-14 01:59:22 +00:00
next-image-new.test.ts fix: add missing <preload> for next/image in App Router (#52425) 2023-07-14 15:36:35 +00:00
next-server-utils.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
next-swc.test.ts Add nodejs version check (#58958) 2023-11-27 16:53:26 +00:00
oxford-comma.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
page-route-sorter.test.ts chore: update ESLint and plugins to latest (#61544) 2024-02-01 20:06:02 -05:00
parse-page-static-info.test.ts Always call createPagesMapping for root paths (#60107) 2024-01-02 15:20:05 +01:00
parse-relative-url.test.ts fix(#33081): handle relative path correctly (#36823) 2022-05-22 16:43:48 +00:00
phaseConstants.test.ts Move unit tests to one folder and migrate them to TypeScript (#28427) 2021-08-24 07:52:45 -05:00
preserve-process-env.test.ts Do not re-assign process.env (#46914) 2023-03-09 14:41:50 -08:00
recursive-copy.test.ts Fix windows unit tests (#53412) 2023-07-31 18:06:18 -07:00
recursive-delete.test.ts File Reader Improvements (#54645) 2023-08-28 18:09:56 +00:00
recursive-readdir.test.ts File Reader Improvements (#54645) 2023-08-28 18:09:56 +00:00
router-add-base-path.test.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
split-cookies-string.test.ts Allow custom path for preview mode cookies (#38313) 2022-08-07 20:45:30 -05:00
validate-url.test.ts Fix canonical url for dynamic routes (#49512) 2023-05-09 16:31:06 -07:00
warn-removed-experimental-config.test.ts chore: update ESLint and plugins to latest (#61544) 2024-02-01 20:06:02 -05:00
webpack-config-overrides.test.ts Update to leverage turbo for build/prepublish (#37280) 2022-05-30 19:05:27 -05:00
write-app-declarations.test.ts refactor: rename isAppDirEnabled to hasAppDir (#62837) 2024-03-05 18:58:53 +01:00