From c4b0302acf7517e7955bcc7d9f2c43b9bd51af8c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Mar 2015 14:49:32 -0700 Subject: [PATCH 1/2] Clean up diagnostic timers and -diagnostic output --- src/compiler/program.ts | 52 +++++++++++++++++++++++------------------ src/compiler/tsc.ts | 39 ++++++++++++------------------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9b933cacf74..eda6833e771 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2,8 +2,10 @@ /// module ts { + /* @internal */ export var programTime = 0; /* @internal */ export var emitTime = 0; /* @internal */ export var ioReadTime = 0; + /* @internal */ export var ioWriteTime = 0; /** The version of the TypeScript compiler release */ export var version = "1.5.0.0"; @@ -35,33 +37,34 @@ module ts { } text = ""; } - return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined; } + function directoryExists(directoryPath: string): boolean { + if (hasProperty(existingDirectories, directoryPath)) { + return true; + } + if (sys.directoryExists(directoryPath)) { + existingDirectories[directoryPath] = true; + return true; + } + return false; + } + + function ensureDirectoriesExist(directoryPath: string) { + if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { + var parentDirectory = getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory); + sys.createDirectory(directoryPath); + } + } + function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { - function directoryExists(directoryPath: string): boolean { - if (hasProperty(existingDirectories, directoryPath)) { - return true; - } - if (sys.directoryExists(directoryPath)) { - existingDirectories[directoryPath] = true; - return true; - } - return false; - } - - function ensureDirectoriesExist(directoryPath: string) { - if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { - var parentDirectory = getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - sys.createDirectory(directoryPath); - } - } - try { + var start = new Date().getTime(); ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); sys.writeFile(fileName, data, writeByteOrderMark); + ioWriteTime += new Date().getTime() - start; } catch (e) { if (onError) { @@ -119,16 +122,19 @@ module ts { var diagnostics = createDiagnosticCollection(); var seenNoDefaultLib = options.noLib; var commonSourceDirectory: string; + var diagnosticsProducingTypeChecker: TypeChecker; + var noDiagnosticsTypeChecker: TypeChecker; + host = host || createCompilerHost(options); + var start = new Date().getTime(); forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); } - verifyCompilerOptions(); + programTime += new Date().getTime() - start; - var diagnosticsProducingTypeChecker: TypeChecker; - var noDiagnosticsTypeChecker: TypeChecker; + verifyCompilerOptions(); program = { getSourceFile: getSourceFile, diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e9c5e17c751..3f82d6c8cf5 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -320,22 +320,16 @@ module ts { } function compile(fileNames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) { - ts.ioReadTime = 0; - ts.parseTime = 0; - ts.bindTime = 0; - ts.checkTime = 0; - ts.emitTime = 0; - - var start = new Date().getTime(); + ioReadTime = 0; + ioWriteTime = 0; + programTime = 0; + bindTime = 0; + checkTime = 0; + emitTime = 0; var program = createProgram(fileNames, compilerOptions, compilerHost); - var programTime = new Date().getTime() - start; - var exitStatus = compileProgram(); - var end = new Date().getTime() - start; - var compileTime = end - programTime; - if (compilerOptions.listFiles) { forEach(program.getSourceFiles(), file => { sys.write(file.fileName + sys.newLine); @@ -356,19 +350,16 @@ module ts { } // Individual component times. - // Note: we output 'programTime' as parseTime to match the tsc 1.3 behavior. tsc 1.3 - // measured parse time along with read IO as a single counter. We preserve that - // behavior so we can accurately compare times. For actual parse times (in isolation) - // is reported below. + // Note: To match the behavior of previous versions of the compiler, the reported parse time includes + // I/O read time and processing time for triple-slash references and module imports, and the reported + // emit time includes I/O write time. We preserve this behavior so we can accurately compare times. + reportTimeStatistic("I/O read", ioReadTime); + reportTimeStatistic("I/O write", ioWriteTime); reportTimeStatistic("Parse time", programTime); - reportTimeStatistic("Bind time", ts.bindTime); - reportTimeStatistic("Check time", ts.checkTime); - reportTimeStatistic("Emit time", ts.emitTime); - - reportTimeStatistic("Parse time w/o IO", ts.parseTime); - reportTimeStatistic("IO read", ts.ioReadTime); - reportTimeStatistic("Compile time", compileTime); - reportTimeStatistic("Total time", end); + reportTimeStatistic("Bind time", bindTime); + reportTimeStatistic("Check time", checkTime); + reportTimeStatistic("Emit time", emitTime); + reportTimeStatistic("Total time", programTime + bindTime + checkTime + emitTime); } return { program, exitStatus }; From 99a6f2b194a92bc3a0753b0bc5ce01c4c4638e03 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Mar 2015 14:49:54 -0700 Subject: [PATCH 2/2] Removing unused function from emitter --- src/compiler/emitter.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8947314a6f6..a592c033c22 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4999,14 +4999,6 @@ module ts { } } - function getFirstExportAssignment(sourceFile: SourceFile) { - return forEach(sourceFile.statements, node => { - if (node.kind === SyntaxKind.ExportAssignment) { - return node; - } - }); - } - function sortAMDModules(amdModules: {name: string; path: string}[]) { // AMD modules with declared variable names go first return amdModules.sort((moduleA, moduleB) => {