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 chunk assignment performance #4736

Merged
merged 5 commits into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/run/batchWarnings.ts
@@ -1,6 +1,6 @@
import type { RollupWarning } from '../../src/rollup/types';
import { bold, gray, yellow } from '../../src/utils/colors';
import { getOrCreate } from '../../src/utils/getOrCreate';
import { getNewArray, getOrCreate } from '../../src/utils/getOrCreate';
import { printQuotedStringList } from '../../src/utils/printStringList';
import relativeId from '../../src/utils/relativeId';
import { stderr } from '../logging';
Expand All @@ -23,7 +23,7 @@ export default function batchWarnings(): BatchWarnings {
warningOccurred = true;

if (warning.code! in deferredHandlers) {
getOrCreate(deferredWarnings, warning.code!, () => []).push(warning);
getOrCreate(deferredWarnings, warning.code!, getNewArray).push(warning);
} else if (warning.code! in immediateHandlers) {
immediateHandlers[warning.code!](warning);
} else {
Expand Down Expand Up @@ -220,7 +220,7 @@ const deferredHandlers: {

const dependencies = new Map<string, string[]>();
for (const warning of warnings) {
getOrCreate(dependencies, relativeId(warning.exporter!), () => []).push(
getOrCreate(dependencies, relativeId(warning.exporter!), getNewArray).push(
relativeId(warning.id!)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Chunk.ts
Expand Up @@ -41,7 +41,7 @@ import { assignExportsToMangledNames, assignExportsToNames } from './utils/expor
import type { GenerateCodeSnippets } from './utils/generateCodeSnippets';
import getExportMode from './utils/getExportMode';
import getIndentString from './utils/getIndentString';
import { getOrCreate } from './utils/getOrCreate';
import { getNewArray, getOrCreate } from './utils/getOrCreate';
import { getStaticDependencies } from './utils/getStaticDependencies';
import type { HashPlaceholderGenerator } from './utils/hashPlaceholders';
import { replacePlaceholders } from './utils/hashPlaceholders';
Expand Down Expand Up @@ -911,7 +911,7 @@ export default class Chunk {
dependency = this.chunkByModule.get(module)!;
imported = dependency.getVariableExportName(variable);
}
getOrCreate(importsByDependency, dependency, () => []).push({
getOrCreate(importsByDependency, dependency, getNewArray).push({
imported,
local: variable.getName(this.snippets.getPropertyAccess)
});
Expand Down Expand Up @@ -1023,7 +1023,7 @@ export default class Chunk {
(imported !== 'default' || isDefaultAProperty(interop(module.id), true));
}
}
getOrCreate(reexportSpecifiers, dependency, () => []).push({
getOrCreate(reexportSpecifiers, dependency, getNewArray).push({
imported,
needsLiveBinding,
reexported: exportName
Expand Down
8 changes: 4 additions & 4 deletions src/Module.ts
Expand Up @@ -63,7 +63,7 @@ import {
warnDeprecation
} from './utils/error';
import { getId } from './utils/getId';
import { getOrCreate } from './utils/getOrCreate';
import { getNewSet, getOrCreate } from './utils/getOrCreate';
import { getOriginalLocation } from './utils/getOriginalLocation';
import { makeLegal } from './utils/identifierHelpers';
import {
Expand Down Expand Up @@ -164,10 +164,10 @@ function getVariableForExportNameRecursive(
}

function getAndExtendSideEffectModules(variable: Variable, module: Module): Set<Module> {
const sideEffectModules = getOrCreate(
const sideEffectModules = getOrCreate<Variable, Set<Module>>(
module.sideEffectDependenciesByVariable,
variable,
() => new Set()
getNewSet
);
let currentVariable: Variable | null = variable;
const referencedVariables = new Set([currentVariable]);
Expand Down Expand Up @@ -613,7 +613,7 @@ export default class Module {
getOrCreate(
importerForSideEffects.sideEffectDependenciesByVariable,
variable,
() => new Set()
getNewSet
).add(this);
setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ast/utils/PathTracker.ts
@@ -1,4 +1,4 @@
import { getOrCreate } from '../../utils/getOrCreate';
import { getNewSet, getOrCreate } from '../../utils/getOrCreate';
import type { Entity } from '../Entity';

export const UnknownKey = Symbol('Unknown Key');
Expand Down Expand Up @@ -98,7 +98,7 @@ export class DiscriminatedPathTracker {
currentPaths[pathSegment] ||
Object.create(null, { [EntitiesKey]: { value: new Map<unknown, Set<Entity>>() } });
}
const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, () => new Set());
const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, getNewSet);
if (trackedEntities.has(entity)) return true;
trackedEntities.add(entity);
return false;
Expand Down