Skip to content

Commit 8ba046a

Browse files
jriekenjoaomoreno
andauthored
print heap stats instead of memory usage (microsoft#203959)
* print heap stats instead of memory usage * ensure no hanging on to service --------- Co-authored-by: João Moreno <[email protected]>
1 parent 442c133 commit 8ba046a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

build/lib/mangle/index.js

Lines changed: 7 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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import * as v8 from 'node:v8';
67
import * as fs from 'fs';
78
import * as path from 'path';
89
import { argv } from 'process';
@@ -338,17 +339,16 @@ class DeclarationData {
338339
constructor(
339340
readonly fileName: string,
340341
readonly node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.EnumDeclaration | ts.VariableDeclaration,
341-
private readonly service: ts.LanguageService,
342342
fileIdents: ShortIdent,
343343
) {
344344
// Todo: generate replacement names based on usage count, with more used names getting shorter identifiers
345345
this.replacementName = fileIdents.next();
346346
}
347347

348-
get locations(): Iterable<{ fileName: string; offset: number }> {
348+
getLocations(service: ts.LanguageService): Iterable<{ fileName: string; offset: number }> {
349349
if (ts.isVariableDeclaration(this.node)) {
350350
// If the const aliases any types, we need to rename those too
351-
const definitionResult = this.service.getDefinitionAndBoundSpan(this.fileName, this.node.name.getStart());
351+
const definitionResult = service.getDefinitionAndBoundSpan(this.fileName, this.node.name.getStart());
352352
if (definitionResult?.definitions && definitionResult.definitions.length > 1) {
353353
return definitionResult.definitions.map(x => ({ fileName: x.fileName, offset: x.textSpan.start }));
354354
}
@@ -471,7 +471,7 @@ export class Mangler {
471471
return;
472472
}
473473

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

@@ -620,7 +620,7 @@ export class Mangler {
620620
}
621621

622622
const newText = data.replacementName;
623-
for (const { fileName, offset } of data.locations) {
623+
for (const { fileName, offset } of data.getLocations(service)) {
624624
queueRename(fileName, offset, newText);
625625
}
626626
}
@@ -723,7 +723,8 @@ export class Mangler {
723723

724724
service.dispose();
725725
this.renameWorkerPool.terminate();
726-
this.log(`Done: ${savedBytes / 1000}kb saved, memory-usage: ${JSON.stringify(process.memoryUsage())}`);
726+
727+
this.log(`Done: ${savedBytes / 1000}kb saved, memory-usage: ${JSON.stringify(v8.getHeapStatistics())}`);
727728
return result;
728729
}
729730
}

0 commit comments

Comments
 (0)