Skip to content

Commit 7da8f74

Browse files
committed
Merge branch 'transforms-visitEachChildPerf' into transforms-binderPerf
2 parents f36ffb9 + 5fbb326 commit 7da8f74

17 files changed

Lines changed: 219 additions & 397 deletions

File tree

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ namespace ts {
8686
const binder = createBinder();
8787

8888
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
89-
performance.mark("bindStart");
89+
const bindStart = performance.mark();
9090
binder(file, options);
91-
performance.measure("bindTime", "bindStart");
91+
performance.measure("bindTime", bindStart);
9292
}
9393

9494
function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16512,11 +16512,11 @@ namespace ts {
1651216512
}
1651316513

1651416514
function checkSourceFile(node: SourceFile) {
16515-
performance.mark("checkStart");
16515+
const checkStart = performance.mark();
1651616516

1651716517
checkSourceFileWorker(node);
1651816518

16519-
performance.measure("checkTime", "checkStart");
16519+
performance.measure("checkTime", checkStart);
1652016520
}
1652116521

1652216522
// Fully type check a source file and collect the relevant diagnostics.

src/compiler/comments.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ namespace ts {
8282
function getLeadingComments(range: TextRange): CommentRange[];
8383
function getLeadingComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean, getTextRangeCallback: (contextNode: Node) => TextRange): CommentRange[];
8484
function getLeadingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange) {
85-
let comments: CommentRange[] = [];
86-
let ignored = false;
8785
if (contextNode) {
8886
range = getTextRangeCallback(contextNode) || range;
8987
if (ignoreNodeCallback(contextNode)) {
90-
ignored = true;
9188
// If the node will not be emitted in JS, remove all the comments (normal,
9289
// pinned and `///`) associated with the node, unless it is a triple slash
9390
// comment at the top of the file.
@@ -101,16 +98,14 @@ namespace ts {
10198
// The first `///` will NOT be removed while the second one will be removed
10299
// even though both nodes will not be emitted.
103100
if (range.pos === 0) {
104-
comments = filter(getLeadingCommentsOfPosition(0), isTripleSlashComment);
101+
return filter(getLeadingCommentsOfPosition(0), isTripleSlashComment);
105102
}
106-
}
107-
}
108103

109-
if (!ignored) {
110-
comments = getLeadingCommentsOfPosition(range.pos);
104+
return;
105+
}
111106
}
112107

113-
return comments;
108+
return getLeadingCommentsOfPosition(range.pos);
114109
}
115110

116111
/**
@@ -277,42 +272,42 @@ namespace ts {
277272
reset,
278273
setSourceFile,
279274
getLeadingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange): CommentRange[] {
280-
performance.mark("commentStart");
275+
const commentStart = performance.mark();
281276
const comments = getLeadingComments(range, contextNode, ignoreNodeCallback, getTextRangeCallback);
282-
performance.measure("commentTime", "commentStart");
277+
performance.measure("commentTime", commentStart);
283278
return comments;
284279
},
285280
getTrailingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange): CommentRange[] {
286-
performance.mark("commentStart");
281+
const commentStart = performance.mark();
287282
const comments = getTrailingComments(range, contextNode, ignoreNodeCallback, getTextRangeCallback);
288-
performance.measure("commentTime", "commentStart");
283+
performance.measure("commentTime", commentStart);
289284
return comments;
290285
},
291286
getTrailingCommentsOfPosition(pos: number): CommentRange[] {
292-
performance.mark("commentStart");
287+
const commentStart = performance.mark();
293288
const comments = getTrailingCommentsOfPosition(pos);
294-
performance.measure("commentTime", "commentStart");
289+
performance.measure("commentTime", commentStart);
295290
return comments;
296291
},
297292
emitLeadingComments(range: TextRange, comments: CommentRange[], contextNode?: Node, getTextRangeCallback?: (contextNode: Node) => TextRange): void {
298-
performance.mark("commentStart");
293+
const commentStart = performance.mark();
299294
emitLeadingComments(range, comments, contextNode, getTextRangeCallback);
300-
performance.measure("commentTime", "commentStart");
295+
performance.measure("commentTime", commentStart);
301296
},
302297
emitTrailingComments(range: TextRange, comments: CommentRange[]): void {
303-
performance.mark("commentStart");
304-
emitLeadingComments(range, comments);
305-
performance.measure("commentTime", "commentStart");
298+
const commentStart = performance.mark();
299+
emitTrailingComments(range, comments);
300+
performance.measure("commentTime", commentStart);
306301
},
307302
emitLeadingDetachedComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean): void {
308-
performance.mark("commentStart");
303+
const commentStart = performance.mark();
309304
emitLeadingDetachedComments(range, contextNode, ignoreNodeCallback);
310-
performance.measure("commentTime", "commentStart");
305+
performance.measure("commentTime", commentStart);
311306
},
312307
emitTrailingDetachedComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean): void {
313-
performance.mark("commentStart");
308+
const commentStart = performance.mark();
314309
emitTrailingDetachedComments(range, contextNode, ignoreNodeCallback);
315-
performance.measure("commentTime", "commentStart");
310+
performance.measure("commentTime", commentStart);
316311
}
317312
};
318313
}

src/compiler/core.ts

Lines changed: 49 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,18 @@ namespace ts {
11201120
}
11211121
}
11221122

1123+
export function getEnvironmentVariable(name: string, host?: CompilerHost) {
1124+
if (host && host.getEnvironmentVariable) {
1125+
return host.getEnvironmentVariable(name);
1126+
}
1127+
1128+
if (sys && sys.getEnvironmentVariable) {
1129+
return sys.getEnvironmentVariable(name);
1130+
}
1131+
1132+
return "";
1133+
}
1134+
11231135
export function copyListRemovingItem<T>(item: T, list: T[]) {
11241136
const copiedList: T[] = [];
11251137
for (const e of list) {
@@ -1139,168 +1151,77 @@ namespace ts {
11391151
/** Performance measurements for the compiler. */
11401152
/*@internal*/
11411153
export namespace performance {
1142-
interface MarkData {
1143-
markName: string;
1144-
timestamp: number;
1145-
}
1146-
1147-
interface MeasureData {
1148-
measureName: string;
1149-
startMarkName: string;
1150-
endMarkName: string;
1151-
timestamp: number;
1152-
marksOffset: number;
1153-
}
1154-
1155-
export interface Measure {
1156-
name: string;
1157-
startTime: number;
1158-
duration: number;
1159-
}
1160-
1161-
const markTimestamps: Map<number> = {};
1162-
const markCounts: Map<number> = {};
1163-
const measureDurations: Map<number> = {};
1164-
1165-
let start = now();
1166-
let enabled = false;
1167-
1168-
/** Gets the current timer for performance measurements. */
1169-
export function now() {
1170-
return Date.now();
1171-
}
1154+
let counters: Map<number>;
1155+
let measures: Map<number>;
11721156

11731157
/**
1174-
* Adds a performance mark with the specified name.
1158+
* Increments a counter with the specified name.
11751159
*
1176-
* @param markName The name of the performance mark.
1160+
* @param counterName The name of the counter.
11771161
*/
1178-
export function mark(markName: string) {
1179-
if (enabled) {
1180-
markTimestamps[markName] = now();
1181-
markCounts[markName] = getCount(markName) + 1;
1162+
export function increment(counterName: string) {
1163+
if (counters) {
1164+
counters[counterName] = (getProperty(counters, counterName) || 0) + 1;
11821165
}
11831166
}
11841167

11851168
/**
1186-
* Gets the names of all marks.
1187-
*/
1188-
export function getMarkNames() {
1189-
return getKeys(markCounts);
1190-
}
1191-
1192-
/**
1193-
* Gets the number of marks with the specified name.
1169+
* Gets the value of the counter with the specified name.
11941170
*
1195-
* @param markName The name of the marks that should be counted.
1171+
* @param counterName The name of the counter.
11961172
*/
1197-
export function getCount(markName: string) {
1198-
return enabled && getProperty(markCounts, markName) || 0;
1173+
export function getCount(counterName: string) {
1174+
return counters && getProperty(counters, counterName) || 0;
11991175
}
12001176

12011177
/**
1202-
* Gets the most recent timestamp for the marks with the specified name.
1203-
*
1204-
* @param markName The name of the mark.
1178+
* Marks the start of a performance measurement.
12051179
*/
1206-
export function getTimestamp(markName: string) {
1207-
return enabled && getProperty(markTimestamps, markName) || 0;
1208-
}
1209-
1210-
/**
1211-
* Clears performance marks.
1212-
*
1213-
* @param markName The name of the mark whose time values should be cleared. If not
1214-
* specified, all marks will be cleared.
1215-
*/
1216-
export function clearMarks(markName?: string) {
1217-
if (markName === undefined) {
1218-
forEachKey(markTimestamps, clearMark);
1219-
}
1220-
else {
1221-
clearMark(markName);
1222-
}
1223-
}
1224-
1225-
function clearMark(markName: string) {
1226-
if (delete markTimestamps[markName]) {
1227-
delete markCounts[markName];
1228-
}
1180+
export function mark() {
1181+
return measures ? Date.now() : 0;
12291182
}
12301183

12311184
/**
12321185
* Adds a performance measurement with the specified name.
12331186
*
12341187
* @param measureName The name of the performance measurement.
1235-
* @param startMarkName The name of the starting mark.
1236-
* If provided, the most recent time value of the start mark is used.
1237-
* If not specified, the value is the time that the performance service was
1238-
* initialized or the last time it was reset.
1239-
* @param endMarkName The name of the ending mark.
1240-
* If provided, the most recent time value of the end mark is used.
1241-
* If not specified, the current time is used.
1188+
* @param marker The timestamp of the starting mark.
12421189
*/
1243-
export function measure(measureName: string, startMarkName?: string, endMarkName?: string) {
1244-
if (enabled) {
1245-
const startTime = startMarkName ? getTimestamp(startMarkName) : start;
1246-
const endTime = endMarkName ? getTimestamp(endMarkName) : now();
1247-
const duration = endTime - startTime;
1248-
measureDurations[measureName] = getDuration(measureName) + duration;
1190+
export function measure(measureName: string, marker: number) {
1191+
if (measures) {
1192+
measures[measureName] = (getProperty(measures, measureName) || 0) + (mark() - marker);
12491193
}
12501194
}
12511195

1252-
/**
1253-
* Gets the names of all recorded measures.
1254-
*/
1255-
export function getMeasureNames() {
1256-
return getKeys(measureDurations);
1257-
}
1258-
12591196
/**
12601197
* Gets the total duration of all measurements with the supplied name.
12611198
*
12621199
* @param measureName The name of the measure whose durations should be accumulated.
12631200
*/
12641201
export function getDuration(measureName: string) {
1265-
return enabled && getProperty(measureDurations, measureName) || 0;
1202+
return measures && getProperty(measures, measureName) || 0;
12661203
}
12671204

1268-
/**
1269-
* Clears performance measures.
1270-
*
1271-
* @param measureName The name of the measure whose durations should be cleared. If not
1272-
* specified, all measures will be cleared.
1273-
*/
1274-
export function clearMeasures(measureName?: string) {
1275-
if (measureName === undefined) {
1276-
forEachKey(measureDurations, clearMeasure);
1277-
}
1278-
else {
1279-
clearMeasure(measureName);
1280-
}
1281-
}
1282-
1283-
function clearMeasure(measureName: string) {
1284-
delete measureDurations[measureName];
1285-
}
1286-
1287-
/**
1288-
* Resets all marks and measurements in the performance service.
1289-
*/
1290-
export function reset() {
1291-
clearMarks();
1292-
clearMeasures();
1293-
start = now();
1294-
}
1295-
1296-
/** Enables performance measurements for the compiler. */
1205+
/** Enables (and resets) performance measurements for the compiler. */
12971206
export function enable() {
1298-
enabled = true;
1299-
}
1300-
1301-
/** Disables performance measurements for the compiler. */
1207+
counters = { };
1208+
measures = {
1209+
programTime: 0,
1210+
parseTime: 0,
1211+
bindTime: 0,
1212+
emitTime: 0,
1213+
ioReadTime: 0,
1214+
ioWriteTime: 0,
1215+
printTime: 0,
1216+
commentTime: 0,
1217+
sourceMapTime: 0
1218+
};
1219+
}
1220+
1221+
/** Disables (and clears) performance measurements for the compiler. */
13021222
export function disable() {
1303-
enabled = false;
1223+
counters = undefined;
1224+
measures = undefined;
13041225
}
13051226
}
13061227
}

0 commit comments

Comments
 (0)