Skip to content

Commit 0c62489

Browse files
authored
Merge pull request microsoft#203536 from microsoft/joh/continuous-gerbil
log memory usage after each mangling step
2 parents 9d6d60f + b7d1c33 commit 0c62489

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

build/lib/mangle/index.js

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/mangle/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,13 @@ export class Mangler {
399399
private readonly allClassDataByKey = new Map<string, ClassData>();
400400
private readonly allExportedSymbols = new Set<DeclarationData>();
401401

402-
private readonly service: ts.LanguageService;
403402
private readonly renameWorkerPool: workerpool.WorkerPool;
404403

405404
constructor(
406405
private readonly projectPath: string,
407406
private readonly log: typeof console.log = () => { },
408407
private readonly config: { readonly manglePrivateFields: boolean; readonly mangleExports: boolean },
409408
) {
410-
this.service = ts.createLanguageService(new StaticLanguageServiceHost(projectPath));
411409

412410
this.renameWorkerPool = workerpool.pool(path.join(__dirname, 'renameWorker.js'), {
413411
maxWorkers: 1,
@@ -417,6 +415,8 @@ export class Mangler {
417415

418416
async computeNewFileContents(strictImplicitPublicHandling?: Set<string>): Promise<Map<string, MangleOutput>> {
419417

418+
const service = ts.createLanguageService(new StaticLanguageServiceHost(this.projectPath));
419+
420420
// STEP:
421421
// - Find all classes and their field info.
422422
// - Find exported symbols.
@@ -471,14 +471,14 @@ export class Mangler {
471471
return;
472472
}
473473

474-
this.allExportedSymbols.add(new DeclarationData(node.getSourceFile().fileName, node, this.service, fileIdents));
474+
this.allExportedSymbols.add(new DeclarationData(node.getSourceFile().fileName, node, service, fileIdents));
475475
}
476476
}
477477

478478
ts.forEachChild(node, visit);
479479
};
480480

481-
for (const file of this.service.getProgram()!.getSourceFiles()) {
481+
for (const file of service.getProgram()!.getSourceFiles()) {
482482
if (!file.isDeclarationFile) {
483483
ts.forEachChild(file, visit);
484484
}
@@ -495,7 +495,7 @@ export class Mangler {
495495
return;
496496
}
497497

498-
const info = this.service.getDefinitionAtPosition(data.fileName, extendsClause.types[0].expression.getEnd());
498+
const info = service.getDefinitionAtPosition(data.fileName, extendsClause.types[0].expression.getEnd());
499499
if (!info || info.length === 0) {
500500
// throw new Error('SUPER type not found');
501501
return;
@@ -641,9 +641,9 @@ export class Mangler {
641641
const result = new Map<string, MangleOutput>();
642642
let savedBytes = 0;
643643

644-
for (const item of this.service.getProgram()!.getSourceFiles()) {
644+
for (const item of service.getProgram()!.getSourceFiles()) {
645645

646-
const { mapRoot, sourceRoot } = this.service.getProgram()!.getCompilerOptions();
646+
const { mapRoot, sourceRoot } = service.getProgram()!.getCompilerOptions();
647647
const projectDir = path.dirname(this.projectPath);
648648
const sourceMapRoot = mapRoot ?? pathToFileURL(sourceRoot ?? projectDir).toString();
649649

@@ -721,7 +721,9 @@ export class Mangler {
721721
result.set(item.fileName, { out: newFullText, sourceMap: generator?.toString() });
722722
}
723723

724-
this.log(`Done: ${savedBytes / 1000}kb saved`);
724+
service.dispose();
725+
this.renameWorkerPool.terminate();
726+
this.log(`Done: ${savedBytes / 1000}kb saved, memory-usage: ${JSON.stringify(process.memoryUsage())}`);
725727
return result;
726728
}
727729
}

0 commit comments

Comments
 (0)