Commit Graph

2 Commits

Author SHA1 Message Date
Tim Neutkens 6e51845ac4 Rename process.env.TURBOPACK to process.env.IS_TURBOPACK_TEST for tests (#77892)
Preparation for removing `process.env.TURBOPACK` being added to
Turbopack tests. That way we can properly test `next start` without
`process.env.TURBOPACK` being set.

<!-- 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 #

-->
2025-04-07 14:07:55 +02:00
Jude Gao 31c047d082 feat: slow module detection for webpack (#75368)
## Problem
During development, certain modules can take an unexpectedly long time
to compile, significantly impacting build performance. Currently,
developers have no visibility into which modules are causing these
slowdowns, making it difficult to optimize their codebase.

## Solution
This PR introduces a new experimental feature that detects and reports
modules that are slow to compile during webpack builds. When enabled,
it:

- Tracks build time for each module
- Reports modules that exceed a configurable time threshold
- Shows a dependency tree visualization of slow modules
- Helps developers identify performance bottlenecks in their build
process

### Configuration
Enable in `next.config.js`:
```js
module.exports = {
  experimental: {
    slowModuleDetection: {
      buildTimeThresholdMs: 500,  // Time threshold to consider a module "slow"
    }
  }
}
```


### Example Output


![image](https://github.com/user-attachments/assets/c01f03fa-5b09-4ad1-af2e-255ed029c568)

## Implementation Details
- Implements a new webpack plugin (`SlowModuleDetectionPlugin`) that
hooks into the compilation process
- Uses webpack's module graph to build a dependency tree of slow modules
- Provides clear, actionable output to help developers optimize their
builds
- Adds comprehensive error handling with detailed error messages
- Includes e2e tests to ensure reliability

## Limitations
- **To ensure accurate measurements, we will set the
[parallelism](https://webpack.js.org/configuration/other-options/#parallelism)
option to 1 in the Webpack configuration (see [Webpack
documentation](https://webpack.js.org/configuration/other-options/#parallelism))
when the feature is enabled. This may significantly slow down
development performance, but it will help surface issues proportionally
to their normal duration.**
- Currently only supports webpack builds. Turbopack support will be
added in a future PR
- Only tracks module build time, not other compilation steps
- Thresholds may need tuning based on project size and complexity


https://linear.app/vercel/issue/NDX-86/slow-module-detection
2025-01-28 10:56:33 -05:00