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

Improve chunking performance #4862

Merged
merged 11 commits into from
Feb 18, 2023
Merged
1 change: 0 additions & 1 deletion build-plugins/add-cli-entry.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ export default function addCliEntry(): Plugin {
});
},
name: 'add-cli-entry',
//@ts-expect-error sourcesContent was changed to allow for null elements in recent versions of magic-string.
renderChunk(code, chunkInfo) {
if (chunkInfo.fileName === CLI_CHUNK) {
const magicString = new MagicString(code);
1 change: 0 additions & 1 deletion build-plugins/conditional-fsevents-import.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ export default function conditionalFsEventsImport(): Plugin {
}
},
name: 'conditional-fs-events-import',
//@ts-expect-error sourcesContent was changed to allow for null elements in recent versions of magic-string.
transform(code, id) {
if (id.endsWith('fsevents-handler.js')) {
transformed = true;
22 changes: 12 additions & 10 deletions docs/configuration-options/index.md
Original file line number Diff line number Diff line change
@@ -2318,16 +2318,6 @@ These options reflect new features that have not yet been fully finalized. Avail

Determines after how many runs cached assets that are no longer used by plugins should be removed.

### experimentalDeepDynamicChunkOptimization

| | |
| --: | :-- |
| Type: | `boolean` |
| CLI: | `--experimentalDeepDynamicChunkOptimization`/`--no-experimentalDeepDynamicChunkOptimization` |
| Default: | `false` |

Currently, chunk generation may create too many chunks if many dynamic imports are used. This is because the algorithm aborts optimization when certain thresholds are surpassed to avoid performance issues. Set this flag to `true` to create potentially fewer chunks at the cost of build performance.

### experimentalMinChunkSize

| | |
@@ -2514,6 +2504,18 @@ _Use the [`renderDynamicImport`](../plugin-development/index.md#renderdynamicimp

This will rename the dynamic import function to the chosen name when outputting ES bundles. This is useful for generating code that uses a dynamic import polyfill such as [this one](https://github.com/uupaa/dynamic-import-polyfill).

### output.experimentalDeepDynamicChunkOptimization

_This option is no longer needed._

| | |
| --: | :-- |
| Type: | `boolean` |
| CLI: | `--experimentalDeepDynamicChunkOptimization`/`--no-experimentalDeepDynamicChunkOptimization` |
| Default: | `false` |

This option was used to prevent performance issues with the full chunk optimization algorithm. As the algorithm is much faster now, this option is now ignored by Rollup and should no longer be used.

### output.preferConst

_Use the [`output.generatedCode.constBindings`](#output-generatedcode-constbindings) option instead._
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@
"pretty-bytes": "^6.0.0",
"pretty-ms": "^8.0.0",
"requirejs": "^2.3.6",
"rollup": "^3.9.1",
"rollup": "^3.16.0",
"rollup-plugin-license": "^3.0.1",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-thatworks": "^1.0.4",
1 change: 0 additions & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
@@ -75,7 +75,6 @@ export default async function (
freeze: false,
generatedCode: 'es2015',
interop: 'default',
manualChunks: { rollup: ['src/node-entry.ts'] },
sourcemap: true
},
plugins: [
12 changes: 3 additions & 9 deletions src/Bundle.ts
Original file line number Diff line number Diff line change
@@ -165,13 +165,8 @@ export default class Bundle {
bundle: OutputBundleWithPlaceholders,
getHashPlaceholder: HashPlaceholderGenerator
): Promise<Chunk[]> {
const {
experimentalDeepDynamicChunkOptimization,
experimentalMinChunkSize,
inlineDynamicImports,
manualChunks,
preserveModules
} = this.outputOptions;
const { experimentalMinChunkSize, inlineDynamicImports, manualChunks, preserveModules } =
this.outputOptions;
const manualChunkAliasByEntry =
typeof manualChunks === 'object'
? await this.addManualChunks(manualChunks)
@@ -193,8 +188,7 @@ export default class Bundle {
: getChunkAssignments(
this.graph.entryModules,
manualChunkAliasByEntry,
experimentalMinChunkSize,
experimentalDeepDynamicChunkOptimization
experimentalMinChunkSize
)) {
sortByExecutionOrder(modules);
const chunk = new Chunk(
6 changes: 3 additions & 3 deletions src/Module.ts
Original file line number Diff line number Diff line change
@@ -166,10 +166,10 @@ function getVariableForExportNameRecursive(
}

function getAndExtendSideEffectModules(variable: Variable, module: Module): Set<Module> {
const sideEffectModules = getOrCreate<Variable, Set<Module>>(
const sideEffectModules = getOrCreate(
module.sideEffectDependenciesByVariable,
variable,
getNewSet
getNewSet<Module>
);
let currentVariable: Variable | null = variable;
const referencedVariables = new Set([currentVariable]);
@@ -616,7 +616,7 @@ export default class Module {
getOrCreate(
importerForSideEffects.sideEffectDependenciesByVariable,
variable,
getNewSet
getNewSet<Module>
).add(this);
setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
}
6 changes: 5 additions & 1 deletion src/ast/utils/PathTracker.ts
Original file line number Diff line number Diff line change
@@ -98,7 +98,11 @@ export class DiscriminatedPathTracker {
currentPaths[pathSegment] ||
Object.create(null, { [EntitiesKey]: { value: new Map<unknown, Set<Entity>>() } });
}
const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, getNewSet);
const trackedEntities = getOrCreate(
currentPaths[EntitiesKey],
discriminator,
getNewSet<Entity>
);
if (trackedEntities.has(entity)) return true;
trackedEntities.add(entity);
return false;
2 changes: 2 additions & 0 deletions src/rollup/types.d.ts
Original file line number Diff line number Diff line change
@@ -653,6 +653,7 @@ export interface OutputOptions {
dynamicImportInCjs?: boolean;
entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
esModule?: boolean | 'if-default-prop';
/** @deprecated This option is no longer needed and ignored. */
experimentalDeepDynamicChunkOptimization?: boolean;
experimentalMinChunkSize?: number;
exports?: 'default' | 'named' | 'none' | 'auto';
@@ -708,6 +709,7 @@ export interface NormalizedOutputOptions {
dynamicImportInCjs: boolean;
entryFileNames: string | ((chunkInfo: PreRenderedChunk) => string);
esModule: boolean | 'if-default-prop';
/** @deprecated This option is no longer needed and ignored. */
experimentalDeepDynamicChunkOptimization: boolean;
experimentalMinChunkSize: number;
exports: 'default' | 'named' | 'none' | 'auto';
Loading
Oops, something went wrong.