Skip to content

Commit

Permalink
Remove experimentalOptimizeChunks
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 29, 2020
1 parent 771189e commit 448852c
Show file tree
Hide file tree
Showing 65 changed files with 2 additions and 690 deletions.
2 changes: 0 additions & 2 deletions docs/01-command-line-reference.md
Expand Up @@ -53,9 +53,7 @@ export default { // can be an array (for multiple inputs)
treeshake,

// experimental
chunkGroupingSize,
experimentalCacheExpiry,
experimentalOptimizeChunks,
perf,

output: { // required (can be an array, for multiple outputs)
Expand Down
2 changes: 0 additions & 2 deletions docs/02-javascript-api.md
Expand Up @@ -96,9 +96,7 @@ const inputOptions = {
treeshake,

// experimental
chunkGroupingSize,
experimentalCacheExpiry,
experimentalOptimizeChunks,
perf
};
```
Expand Down
14 changes: 0 additions & 14 deletions docs/999-big-list-of-options.md
Expand Up @@ -1053,27 +1053,13 @@ In the example, the last line is always retained as accessing the `element` prop

These options reflect new features that have not yet been fully finalized. Availability, behaviour and usage may therefore be subject to change between minor versions.

#### chunkGroupingSize
Type: `number`<br>
CLI: `--chunkGroupingSize <size>`<br>
Default: `5000`

The total source length allowed to be loaded unnecessarily when using `experimentalOptimizeChunks`.

#### experimentalCacheExpiry
Type: `number`<br>
CLI: `--experimentalCacheExpiry <numberOfRuns>`<br>
Default: `10`

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

#### experimentalOptimizeChunks
Type: `boolean`<br>
CLI: `--experimentalOptimizeChunks`/`--no-experimentalOptimizeChunks`<br>
Default: `false`

Experimental feature to optimize chunk groupings. When a large number of chunks are generated, this allows smaller chunks to group together as long as they are within the `chunkGroupingSize` limit. It results in unnecessary code being loaded in some cases in order to have a smaller number of chunks overall. Disabled by default as it may cause unwanted side effects when loading unexpected code.

#### perf
Type: `boolean`<br>
CLI: `--perf`/`--no-perf`<br>
Expand Down
113 changes: 0 additions & 113 deletions src/Chunk.ts
Expand Up @@ -172,7 +172,6 @@ export default class Chunk {
private renderedHash: string = undefined as any;
private renderedModuleSources = new Map<Module, MagicString>();
private renderedSource: MagicStringBundle | null = null;
private renderedSourceLength: number = undefined as any;
private sortedExportNames: string[] | null = null;

constructor(graph: Graph, orderedModules: Module[]) {
Expand Down Expand Up @@ -390,11 +389,6 @@ export default class Chunk {
return (this.renderedHash = hash.digest('hex'));
}

getRenderedSourceLength() {
if (this.renderedSourceLength !== undefined) return this.renderedSourceLength;
return (this.renderedSourceLength = (this.renderedSource as MagicStringBundle).length());
}

getVariableExportName(variable: Variable): string {
if (this.graph.preserveModules && variable instanceof NamespaceVariable) {
return '*';
Expand All @@ -417,112 +411,6 @@ export default class Chunk {
this.dynamicDependencies = Array.from(dynamicDependencies);
}

/*
* Performs a full merge of another chunk into this chunk
* chunkList allows updating references in other chunks for the merged chunk to this chunk
* A new facade will be added to chunkList if tainting exports of either as an entry point
*/
merge(chunk: Chunk, chunkList: Chunk[], options: OutputOptions, inputBase: string) {
if (this.facadeModule !== null || chunk.facadeModule !== null)
throw new Error('Internal error: Code splitting chunk merges not supported for facades');

for (const module of chunk.orderedModules) {
module.chunk = this;
this.orderedModules.push(module);
}

for (const variable of chunk.imports) {
if (!this.imports.has(variable) && (variable.module as Module).chunk !== this) {
this.imports.add(variable);
}
}

// NB detect when exported variables are orphaned by the merge itself
// (involves reverse tracing dependents)
for (const variable of chunk.exports) {
if (!this.exports.has(variable)) {
this.exports.add(variable);
}
}

const thisOldExportNames = this.exportNames;

// regenerate internal names
this.generateInternalExports(options);

const updateRenderedDeclaration = (
dep: ModuleDeclarationDependency,
oldExportNames: Record<string, Variable>
) => {
if (dep.imports) {
for (const impt of dep.imports) {
impt.imported = this.getVariableExportName(oldExportNames[impt.imported]);
}
}
if (dep.reexports) {
for (const reexport of dep.reexports) {
reexport.imported = this.getVariableExportName(oldExportNames[reexport.imported]);
}
}
};

const mergeRenderedDeclaration = (
into: ModuleDeclarationDependency,
from: ModuleDeclarationDependency
) => {
if (from.imports) {
if (!into.imports) {
into.imports = from.imports;
} else {
into.imports = into.imports.concat(from.imports);
}
}
if (from.reexports) {
if (!into.reexports) {
into.reexports = from.reexports;
} else {
into.reexports = into.reexports.concat(from.reexports);
}
}
if (!into.exportsNames && from.exportsNames) {
into.exportsNames = true;
}
if (!into.exportsDefault && from.exportsDefault) {
into.exportsDefault = true;
}
into.name = this.variableName;
};

// go through the other chunks and update their dependencies
// also update their import and reexport names in the process
for (const c of chunkList) {
let includedDeclaration: ModuleDeclarationDependency = undefined as any;
for (let i = 0; i < c.dependencies.length; i++) {
const dep = c.dependencies[i];
if ((dep === chunk || dep === this) && includedDeclaration) {
const duplicateDeclaration = c.renderedDeclarations.dependencies[i];
updateRenderedDeclaration(
duplicateDeclaration,
dep === chunk ? chunk.exportNames : thisOldExportNames
);
mergeRenderedDeclaration(includedDeclaration, duplicateDeclaration);
c.renderedDeclarations.dependencies.splice(i, 1);
c.dependencies.splice(i--, 1);
} else if (dep === chunk) {
c.dependencies[i] = this;
includedDeclaration = c.renderedDeclarations.dependencies[i];
updateRenderedDeclaration(includedDeclaration, chunk.exportNames);
} else if (dep === this) {
includedDeclaration = c.renderedDeclarations.dependencies[i];
updateRenderedDeclaration(includedDeclaration, thisOldExportNames);
}
}
}

// re-render the merged chunk
this.preRender(options, inputBase);
}

// prerender allows chunk hashes and names to be generated before finalizing
preRender(options: OutputOptions, inputBase: string) {
timeStart('render modules', 3);
Expand Down Expand Up @@ -620,7 +508,6 @@ export default class Chunk {
this.renderedSource = magicString.trim();
}

this.renderedSourceLength = undefined as any;
this.renderedHash = undefined as any;

if (this.isEmpty && this.getExportNames().length === 0 && this.dependencies.length === 0) {
Expand Down
138 changes: 0 additions & 138 deletions src/chunk-optimization.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/rollup/rollup.ts
@@ -1,6 +1,5 @@
import { version as rollupVersion } from 'package.json';
import Chunk from '../Chunk';
import { optimizeChunks } from '../chunk-optimization';
import Graph from '../Graph';
import { createAddons } from '../utils/addons';
import { assignChunkIds } from '../utils/assignChunkIds';
Expand Down Expand Up @@ -95,12 +94,6 @@ function getInputOptions(rawInputOptions: GenericConfigObject): InputOptions {
code: 'INVALID_OPTION',
message: '"manualChunks" option is not supported for "inlineDynamicImports".'
});

if (inputOptions.experimentalOptimizeChunks)
return error({
code: 'INVALID_OPTION',
message: '"experimentalOptimizeChunks" option is not supported for "inlineDynamicImports".'
});
if (
(inputOptions.input instanceof Array && inputOptions.input.length > 1) ||
(typeof inputOptions.input === 'object' && Object.keys(inputOptions.input).length > 1)
Expand All @@ -115,11 +108,6 @@ function getInputOptions(rawInputOptions: GenericConfigObject): InputOptions {
code: 'INVALID_OPTION',
message: '"preserveModules" does not support the "manualChunks" option.'
});
if (inputOptions.experimentalOptimizeChunks)
return error({
code: 'INVALID_OPTION',
message: '"preserveModules" does not support the "experimentalOptimizeChunks" option.'
});
}

return inputOptions;
Expand Down Expand Up @@ -195,9 +183,6 @@ export async function rollupInternal(

timeEnd('BUILD', 1);

// ensure we only do one optimization pass per build
let optimized = false;

function getOutputOptionsAndPluginDriver(
rawOutputOptions: GenericConfigObject
): { outputOptions: OutputOptions; outputPluginDriver: PluginDriver } {
Expand Down Expand Up @@ -243,10 +228,6 @@ export async function rollupInternal(
for (const chunk of chunks) {
chunk.preRender(outputOptions, inputBase);
}
if (!optimized && inputOptions.experimentalOptimizeChunks) {
optimizeChunks(chunks, outputOptions, inputOptions.chunkGroupingSize!, inputBase);
optimized = true;
}
assignChunkIds(
chunks,
inputOptions,
Expand Down
2 changes: 0 additions & 2 deletions src/rollup/types.d.ts
Expand Up @@ -385,10 +385,8 @@ export interface InputOptions {
acorn?: any;
acornInjectPlugins?: Function[];
cache?: false | RollupCache;
chunkGroupingSize?: number;
context?: string;
experimentalCacheExpiry?: number;
experimentalOptimizeChunks?: boolean;
external?: ExternalOption;
inlineDynamicImports?: boolean;
input?: InputOption;
Expand Down

0 comments on commit 448852c

Please sign in to comment.