Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rollup/rollup into sync-6…
Browse files Browse the repository at this point in the history
…9353a84
  • Loading branch information
docschina-bot committed Oct 29, 2024
2 parents 5b52aaf + 69353a8 commit 7b41e96
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 55 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# rollup changelog

## 4.24.3

_2024-10-29_

### Bug Fixes

- Slightly reduce memory consumption by specifying fixed array sizes where possible (#5703)

### Pull Requests

- [#5703](https://github.com/rollup/rollup/pull/5703): perf: use pre-allocated arrays for known result sizes (@GalacticHypernova)

## 4.24.2

_2024-10-27_
Expand Down
2 changes: 1 addition & 1 deletion browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/browser",
"version": "4.24.2",
"version": "4.24.3",
"description": "Next-generation ES module bundler browser build",
"main": "dist/rollup.browser.js",
"module": "dist/es/rollup.browser.js",
Expand Down
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "4.24.2",
"version": "4.24.3",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
8 changes: 4 additions & 4 deletions scripts/ast-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,20 @@ export const AST_NODES = {
fields: [['body', 'NodeList']],
scriptedFields: {
body: ` const bodyPosition = $position;
const body: (MethodDefinition | PropertyDefinition)[] = (node.body = []);
if (bodyPosition) {
const length = buffer[bodyPosition];
const body: (MethodDefinition | PropertyDefinition)[] = (node.body = new Array(length));
for (let index = 0; index < length; index++) {
const nodePosition = buffer[bodyPosition + 1 + index];
body.push(
convertNode(
body[index] = convertNode(
node,
(buffer[nodePosition + 3] & 1) === 0 ? scope.instanceScope : scope,
nodePosition,
buffer
)
);
}
} else {
node.body = [];
}`
},
useMacro: false
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-buffer-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ function convertNodeList(
): any[] {
if (position === 0) return EMPTY_ARRAY as never[];
const length = buffer[position++];
const list: any[] = [];
const list: any[] = new Array(length);
for (let index = 0; index < length; index++) {
const nodePosition = buffer[position++];
list.push(nodePosition ? convertNode(parent, parentScope, nodePosition, buffer) : null);
list[index] = nodePosition ? convertNode(parent, parentScope, nodePosition, buffer) : null;
}
return list;
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-buffer-to-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ export function convertNode(position: number, buffer: AstBuffer): any {
function convertNodeList(position: number, buffer: AstBuffer): any[] {
if (position === 0) return EMPTY_ARRAY as never[];
const length = buffer[position++];
const list: any[] = [];
const list: any[] = new Array(length);
for (let index = 0; index < length; index++) {
const nodePosition = buffer[position++];
list.push(nodePosition ? convertNode(nodePosition, buffer) : null);
list[index] = nodePosition ? convertNode(nodePosition, buffer) : null;
}
return list;
}
Expand Down
12 changes: 7 additions & 5 deletions src/Bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ export default class Bundle {
this.outputOptions,
inputBase
);
const chunks: Chunk[] = [];
const chunkByModule = new Map<Module, Chunk>();
for (const { alias, modules } of inlineDynamicImports
const executableModule = inlineDynamicImports
? [{ alias: null, modules: includedModules }]
: preserveModules
? includedModules.map(module => ({ alias: null, modules: [module] }))
Expand All @@ -189,7 +187,11 @@ export default class Bundle {
manualChunkAliasByEntry,
experimentalMinChunkSize,
this.inputOptions.onLog
)) {
);
const chunks: Chunk[] = new Array(executableModule.length);
const chunkByModule = new Map<Module, Chunk>();
let index = 0;
for (const { alias, modules } of executableModule) {
sortByExecutionOrder(modules);
const chunk = new Chunk(
modules,
Expand All @@ -208,7 +210,7 @@ export default class Bundle {
inputBase,
snippets
);
chunks.push(chunk);
chunks[index++] = chunk;
}
for (const chunk of chunks) {
chunk.link();
Expand Down
20 changes: 10 additions & 10 deletions src/ast/bufferParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,20 @@ const bufferParsers: ((node: any, position: number, buffer: AstBuffer) => void)[
function classBody(node: ClassBody, position, buffer) {
const { scope } = node;
const bodyPosition = buffer[position];
const body: (MethodDefinition | PropertyDefinition)[] = (node.body = []);
if (bodyPosition) {
const length = buffer[bodyPosition];
const body: (MethodDefinition | PropertyDefinition)[] = (node.body = new Array(length));
for (let index = 0; index < length; index++) {
const nodePosition = buffer[bodyPosition + 1 + index];
body.push(
convertNode(
node,
(buffer[nodePosition + 3] & 1) === 0 ? scope.instanceScope : scope,
nodePosition,
buffer
)
body[index] = convertNode(
node,
(buffer[nodePosition + 3] & 1) === 0 ? scope.instanceScope : scope,
nodePosition,
buffer
);
}
} else {
node.body = [];
}
},
function classDeclaration(node: ClassDeclaration, position, buffer) {
Expand Down Expand Up @@ -917,10 +917,10 @@ function convertNodeList(
): any[] {
if (position === 0) return EMPTY_ARRAY as never[];
const length = buffer[position++];
const list: any[] = [];
const list: any[] = new Array(length);
for (let index = 0; index < length; index++) {
const nodePosition = buffer[position++];
list.push(nodePosition ? convertNode(parent, parentScope, nodePosition, buffer) : null);
list[index] = nodePosition ? convertNode(parent, parentScope, nodePosition, buffer) : null;
}
return list;
}
13 changes: 6 additions & 7 deletions src/ast/nodes/ClassBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ export default class ClassBody extends NodeBase {
}

parseNode(esTreeNode: GenericEsTreeNode): this {
const body: NodeBase[] = (this.body = []);
const body: NodeBase[] = (this.body = new Array(esTreeNode.body.length));
let index = 0;
for (const definition of esTreeNode.body) {
body.push(
new (this.scope.context.getNodeConstructor(definition.type))(
this,
definition.static ? this.scope : this.scope.instanceScope
).parseNode(definition)
);
body[index++] = new (this.scope.context.getNodeConstructor(definition.type))(
this,
definition.static ? this.scope : this.scope.instanceScope
).parseNode(definition);
}
return super.parseNode(esTreeNode);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/shared/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ export class NodeBase extends ExpressionEntity implements ExpressionNode {
} else if (typeof value !== 'object' || value === null) {
(this as GenericEsTreeNode)[key] = value;
} else if (Array.isArray(value)) {
(this as GenericEsTreeNode)[key] = [];
(this as GenericEsTreeNode)[key] = new Array(value.length);
let index = 0;
for (const child of value) {
(this as GenericEsTreeNode)[key].push(
(this as GenericEsTreeNode)[key][index++] =
child === null
? null
: new (this.scope.context.getNodeConstructor(child.type))(this, this.scope).parseNode(
child
)
);
);
}
} else {
(this as GenericEsTreeNode)[key] = new (this.scope.context.getNodeConstructor(value.type))(
Expand Down
8 changes: 4 additions & 4 deletions src/finalisers/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ function getImportBlock(

function getExportBlock(exports: ChunkExports, { _, cnst }: GenerateCodeSnippets): string[] {
const exportBlock: string[] = [];
const exportDeclaration: string[] = [];
const exportDeclaration: string[] = new Array(exports.length);
let index = 0;
for (const specifier of exports) {
if (specifier.expression) {
exportBlock.push(`${cnst} ${specifier.local}${_}=${_}${specifier.expression};`);
}
exportDeclaration.push(
exportDeclaration[index++] =
specifier.exported === specifier.local
? specifier.local
: `${specifier.local} as ${stringifyIdentifierIfNeeded(specifier.exported)}`
);
: `${specifier.local} as ${stringifyIdentifierIfNeeded(specifier.exported)}`;
}
if (exportDeclaration.length > 0) {
exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/astConverterHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const convertAnnotations = (
): readonly RollupAnnotation[] => {
if (position === 0) return EMPTY_ARRAY;
const length = buffer[position++];
const list: any[] = [];
const list: any[] = new Array(length);
for (let index = 0; index < length; index++) {
list.push(convertAnnotation(buffer[position++], buffer));
list[index] = convertAnnotation(buffer[position++], buffer);
}
return list;
};
Expand Down
4 changes: 2 additions & 2 deletions src/utils/bufferToAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,10 +1103,10 @@ export function convertNode(position: number, buffer: AstBuffer): any {
function convertNodeList(position: number, buffer: AstBuffer): any[] {
if (position === 0) return EMPTY_ARRAY as never[];
const length = buffer[position++];
const list: any[] = [];
const list: any[] = new Array(length);
for (let index = 0; index < length; index++) {
const nodePosition = buffer[position++];
list.push(nodePosition ? convertNode(nodePosition, buffer) : null);
list[index] = nodePosition ? convertNode(nodePosition, buffer) : null;
}
return list;
}
22 changes: 13 additions & 9 deletions src/utils/chunkAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ export function getChunkAssignments(
function getChunkDefinitionsFromManualChunks(
manualChunkAliasByEntry: ReadonlyMap<Module, string>
): { chunkDefinitions: ChunkDefinitions; modulesInManualChunks: Set<Module> } {
const chunkDefinitions: ChunkDefinitions = [];
const modulesInManualChunks = new Set(manualChunkAliasByEntry.keys());
const manualChunkModulesByAlias: Record<string, Module[]> = Object.create(null);
for (const [entry, alias] of manualChunkAliasByEntry) {
Expand All @@ -211,8 +210,11 @@ function getChunkDefinitionsFromManualChunks(
modulesInManualChunks
);
}
for (const [alias, modules] of Object.entries(manualChunkModulesByAlias)) {
chunkDefinitions.push({ alias, modules });
const manualChunks = Object.entries(manualChunkModulesByAlias);
const chunkDefinitions: ChunkDefinitions = new Array(manualChunks.length);
let index = 0;
for (const [alias, modules] of manualChunks) {
chunkDefinitions[index++] = { alias, modules };
}
return { chunkDefinitions, modulesInManualChunks };
}
Expand Down Expand Up @@ -242,12 +244,12 @@ function analyzeModuleGraph(entries: Iterable<Module>): {
} {
const dynamicEntryModules = new Set<Module>();
const dependentEntriesByModule = new Map<Module, Set<number>>();
const dynamicImportModulesByEntry: Set<Module>[] = [];
const allEntriesSet = new Set(entries);
const dynamicImportModulesByEntry: Set<Module>[] = new Array(allEntriesSet.size);
let entryIndex = 0;
for (const currentEntry of allEntriesSet) {
const dynamicImportsForCurrentEntry = new Set<Module>();
dynamicImportModulesByEntry.push(dynamicImportsForCurrentEntry);
dynamicImportModulesByEntry[entryIndex] = dynamicImportsForCurrentEntry;
const modulesToHandle = new Set([currentEntry]);
for (const module of modulesToHandle) {
getOrCreate(dependentEntriesByModule, module, getNewSet<number>).add(entryIndex);
Expand Down Expand Up @@ -307,13 +309,14 @@ function getDynamicEntries(
dynamicEntries.add(entryIndex);
}
}
const dynamicImportsByEntry: Set<number>[] = [];
const dynamicImportsByEntry: Set<number>[] = new Array(dynamicImportModulesByEntry.length);
let index = 0;
for (const dynamicImportModules of dynamicImportModulesByEntry) {
const dynamicImports = new Set<number>();
for (const dynamicEntry of dynamicImportModules) {
dynamicImports.add(entryIndexByModule.get(dynamicEntry)!);
}
dynamicImportsByEntry.push(dynamicImports);
dynamicImportsByEntry[index++] = dynamicImports;
}
return { dynamicEntries, dynamicImportsByEntry };
}
Expand Down Expand Up @@ -464,9 +467,10 @@ function getChunksWithSameDependentEntriesAndCorrelatedAtoms(
) {
const chunksBySignature: Record<string, ChunkDescription> = Object.create(null);
const chunkByModule = new Map<Module, ChunkDescription>();
const sizeByAtom: number[] = [];
const sizeByAtom: number[] = new Array(chunkAtoms.length);
let sideEffectAtoms = 0n;
let atomMask = 1n;
let index = 0;
for (const { dependentEntries, modules } of chunkAtoms) {
let chunkSignature = 0n;
let correlatedAtoms = -1n;
Expand Down Expand Up @@ -505,7 +509,7 @@ function getChunksWithSameDependentEntriesAndCorrelatedAtoms(
if (!pure) {
sideEffectAtoms |= atomMask;
}
sizeByAtom.push(atomSize);
sizeByAtom[index++] = atomSize;

chunk.containedAtoms |= atomMask;
chunk.modules.push(...modules);
Expand Down

0 comments on commit 7b41e96

Please sign in to comment.