mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Wrap performance metrics in object to reduce deoptimizations on ts namespace.
This commit is contained in:
1 parent
60e1ae0e9f
commit
b8a9efb66c
5 files changed
+163
-28
No files matched your search
+14
-14
@@ -4,11 +4,6 @@
|
||||
/// <reference path="printer.ts" />
|
||||
|
||||
namespace ts {
|
||||
/* @internal */ export let programTime = 0;
|
||||
/* @internal */ export let emitTime = 0;
|
||||
/* @internal */ export let ioReadTime = 0;
|
||||
/* @internal */ export let ioWriteTime = 0;
|
||||
|
||||
/** The version of the TypeScript compiler release */
|
||||
|
||||
const emptyArray: any[] = [];
|
||||
@@ -781,9 +776,10 @@ namespace ts {
|
||||
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
|
||||
let text: string;
|
||||
try {
|
||||
const start = new Date().getTime();
|
||||
Performance.mark("ioReadStart");
|
||||
text = sys.readFile(fileName, options.charset);
|
||||
ioReadTime += new Date().getTime() - start;
|
||||
Performance.mark("ioReadEnd");
|
||||
Performance.measure("ioReadTime", "ioReadStart", "ioReadEnd");
|
||||
}
|
||||
catch (e) {
|
||||
if (onError) {
|
||||
@@ -850,7 +846,7 @@ namespace ts {
|
||||
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
|
||||
try {
|
||||
const start = new Date().getTime();
|
||||
Performance.mark("ioWriteStart");
|
||||
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
|
||||
|
||||
if (isWatchSet(options) && sys.createHash && sys.getModifiedTime) {
|
||||
@@ -860,7 +856,8 @@ namespace ts {
|
||||
sys.writeFile(fileName, data, writeByteOrderMark);
|
||||
}
|
||||
|
||||
ioWriteTime += new Date().getTime() - start;
|
||||
Performance.mark("ioWriteEnd");
|
||||
Performance.measure("ioWriteTime", "ioWriteStart", "ioWriteEnd");
|
||||
}
|
||||
catch (e) {
|
||||
if (onError) {
|
||||
@@ -962,7 +959,7 @@ namespace ts {
|
||||
let resolvedTypeReferenceDirectives: Map<ResolvedTypeReferenceDirective> = {};
|
||||
let fileProcessingDiagnostics = createDiagnosticCollection();
|
||||
|
||||
const start = new Date().getTime();
|
||||
Performance.mark("programStart");
|
||||
|
||||
host = host || createCompilerHost(options);
|
||||
|
||||
@@ -1055,7 +1052,8 @@ namespace ts {
|
||||
|
||||
verifyCompilerOptions();
|
||||
|
||||
programTime += new Date().getTime() - start;
|
||||
Performance.mark("programEnd");
|
||||
Performance.measure("programTime", "programStart", "programEnd");
|
||||
|
||||
return program;
|
||||
|
||||
@@ -1288,7 +1286,7 @@ namespace ts {
|
||||
// checked is to not pass the file to getEmitResolver.
|
||||
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile);
|
||||
|
||||
const start = new Date().getTime();
|
||||
Performance.mark("emitStart");
|
||||
|
||||
// TODO(rbuckton): remove USE_TRANSFORMS condition when we switch to transforms permanently.
|
||||
let useLegacyEmitter = options.useLegacyEmitter;
|
||||
@@ -1302,7 +1300,9 @@ namespace ts {
|
||||
getEmitHost(writeFileCallback),
|
||||
sourceFile);
|
||||
|
||||
emitTime += new Date().getTime() - start;
|
||||
Performance.mark("emitEnd");
|
||||
Performance.measure("emitTime", "emitStart", "emitEnd");
|
||||
|
||||
return emitResult;
|
||||
}
|
||||
|
||||
@@ -2076,7 +2076,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Cannot specify module gen that isn't amd or system with --out
|
||||
// Report this error if user specified --module moduleKind
|
||||
// Report this error if user specified --module moduleKind
|
||||
// or if there is external module in compilation which defaults to commonjs
|
||||
const emitModuleKind = getEmitModuleKind(options);
|
||||
if (outFile && (options.module || firstExternalModuleSourceFile) && !(emitModuleKind === ModuleKind.AMD || emitModuleKind === ModuleKind.System)) {
|
||||
|
||||
Reference in new issue
Block a user