922a45839a
This PR changes `fs.stat` calls (to check if a file exists or not) to be aggregated as `fs.readdir` calls and cached during the entire loader pass. This is because we have a huge amount of file to check, but they are always in a small amount of directories. For example, a route that's 5-directory deep (`/a/b/c/d/page.js`) can have up to 4,000 special segments and metadata files to check. However they're always under these 5 directories. So instead of 4,000 `fs.stat` calls let's just do 5 `fs.readdir` calls. Didn't measure it carefully but a quick local test shows a 20~30% improvement. <details> <summary>Another idea for future improvements</summary> Currently, we create a MissingModuleDependency for any combination of possible metadata filename. But in reality, we only need to track them incrementally by index. For example if `icon1.js` is missing, it's kinda waste to still track `icon2.js`~`icon9.js` because `icon1.js` will be added first. This change should at least reduce the number of file watchers by 80% and the initial compilation time by 0.5~1s, depending on the actual route. </details> --------- Co-authored-by: Tim Neutkens <tim@timneutkens.nl> |
||
---|---|---|
.. | ||
compat | ||
font | ||
image-types | ||
legacy | ||
navigation-types/compat | ||
src | ||
types | ||
amp.d.ts | ||
amp.js | ||
app.d.ts | ||
app.js | ||
babel.d.ts | ||
babel.js | ||
cache.d.ts | ||
cache.js | ||
client.d.ts | ||
client.js | ||
config.d.ts | ||
config.js | ||
constants.d.ts | ||
constants.js | ||
document.d.ts | ||
document.js | ||
dynamic.d.ts | ||
dynamic.js | ||
error.d.ts | ||
error.js | ||
head.d.ts | ||
head.js | ||
headers.d.ts | ||
headers.js | ||
image.d.ts | ||
image.js | ||
index.d.ts | ||
jest.d.ts | ||
jest.js | ||
license.md | ||
link.d.ts | ||
link.js | ||
navigation.d.ts | ||
navigation.js | ||
package.json | ||
README.md | ||
router.d.ts | ||
router.js | ||
script.d.ts | ||
script.js | ||
server.d.ts | ||
server.js | ||
taskfile-ncc.js | ||
taskfile-swc.js | ||
taskfile-watch.js | ||
taskfile.js | ||
tsconfig.json | ||
web-vitals.d.ts | ||
web-vitals.js |
Next.js
Getting Started
Visit https://nextjs.org/learn to get started with Next.js.
Documentation
Visit https://nextjs.org/docs to view the full documentation.
Who is using Next.js?
Next.js is used by the world's leading companies. Check out the Next.js Showcase to learn more.
Community
The Next.js community can be found on GitHub Discussions, where you can ask questions, voice ideas, and share your projects.
To chat with other community members you can join the Next.js Discord.
Our Code of Conduct applies to all Next.js community channels.
Contributing
Please see our contributing.md.
Good First Issues
We have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.
Authors
- Tim Neutkens (@timneutkens)
- Naoyuki Kanezawa (@nkzawa)
- Guillermo Rauch (@rauchg)
- Arunoda Susiripala (@arunoda)
- Tony Kovanen (@tonykovanen)
- Dan Zajdband (@impronunciable)
Security
If you believe you have found a security vulnerability in Next.js, we encourage you to responsibly disclose this and not open a public issue. We will investigate all legitimate reports. Email security@vercel.com
to disclose any security vulnerabilities.