Skip to content

Commit 5d4e47f

Browse files
committed
Merge branch 'transforms-fixPerformance' into transforms-visitEachChildPerf
2 parents 2ea6331 + 3c6ceaf commit 5d4e47f

11 files changed

Lines changed: 75 additions & 215 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: 18 additions & 23 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");
298+
const commentStart = performance.mark();
304299
emitLeadingComments(range, comments);
305-
performance.measure("commentTime", "commentStart");
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: 19 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,158 +1139,64 @@ namespace ts {
11391139
/** Performance measurements for the compiler. */
11401140
/*@internal*/
11411141
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();
1142+
let counters: Map<number> = {};
1143+
let measures: Map<number> = {};
11661144
let enabled = false;
11671145

1168-
/** Gets the current timer for performance measurements. */
1169-
export function now() {
1170-
return Date.now();
1171-
}
1172-
11731146
/**
1174-
* Adds a performance mark with the specified name.
1147+
* Increments a counter with the specified name.
11751148
*
1176-
* @param markName The name of the performance mark.
1149+
* @param counterName The name of the counter.
11771150
*/
1178-
export function mark(markName: string) {
1151+
export function increment(counterName: string) {
11791152
if (enabled) {
1180-
markTimestamps[markName] = now();
1181-
markCounts[markName] = getCount(markName) + 1;
1153+
counters[counterName] = (getProperty(counters, counterName) || 0) + 1;
11821154
}
11831155
}
11841156

11851157
/**
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.
1158+
* Gets the value of the counter with the specified name.
11941159
*
1195-
* @param markName The name of the marks that should be counted.
1160+
* @param counterName The name of the counter.
11961161
*/
1197-
export function getCount(markName: string) {
1198-
return enabled && getProperty(markCounts, markName) || 0;
1162+
export function getCount(counterName: string) {
1163+
return enabled && getProperty(counters, counterName) || 0;
11991164
}
12001165

12011166
/**
1202-
* Gets the most recent timestamp for the marks with the specified name.
1203-
*
1204-
* @param markName The name of the mark.
1167+
* Marks the start of a performance measurement.
12051168
*/
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-
}
1169+
export function mark() {
1170+
return enabled ? Date.now() : 0;
12291171
}
12301172

12311173
/**
12321174
* Adds a performance measurement with the specified name.
12331175
*
12341176
* @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.
1177+
* @param marker The timestamp of the starting mark.
12421178
*/
1243-
export function measure(measureName: string, startMarkName?: string, endMarkName?: string) {
1179+
export function measure(measureName: string, marker: number) {
12441180
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;
1181+
measures[measureName] = (getProperty(measures, measureName) || 0) + (mark() - marker);
12491182
}
12501183
}
12511184

1252-
/**
1253-
* Gets the names of all recorded measures.
1254-
*/
1255-
export function getMeasureNames() {
1256-
return getKeys(measureDurations);
1257-
}
1258-
12591185
/**
12601186
* Gets the total duration of all measurements with the supplied name.
12611187
*
12621188
* @param measureName The name of the measure whose durations should be accumulated.
12631189
*/
12641190
export function getDuration(measureName: string) {
1265-
return enabled && getProperty(measureDurations, measureName) || 0;
1266-
}
1267-
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];
1191+
return enabled && getProperty(measures, measureName) || 0;
12851192
}
12861193

12871194
/**
12881195
* Resets all marks and measurements in the performance service.
12891196
*/
12901197
export function reset() {
1291-
clearMarks();
1292-
clearMeasures();
1293-
start = now();
1198+
counters = {};
1199+
measures = {};
12941200
}
12951201

12961202
/** Enables performance measurements for the compiler. */

src/compiler/factory.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,6 @@ namespace ts {
105105
return clone;
106106
}
107107

108-
/**
109-
* Gets a clone of a node with a unique node ID.
110-
*/
111-
export function getUniqueClone<T extends Node>(node: T): T {
112-
const clone = getMutableClone(node);
113-
clone.id = 0;
114-
getNodeId(clone);
115-
return clone;
116-
}
117-
118108
// Literals
119109

120110
export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange): StringLiteral;
@@ -1035,8 +1025,9 @@ namespace ts {
10351025
}
10361026

10371027
function createReactNamespace(reactNamespace: string, parent: JsxOpeningLikeElement) {
1038-
// Create an identifier and give it a parent. This allows us to resolve the react
1039-
// namespace during emit.
1028+
// To ensure the emit resolver can properly resolve the namespace, we need to
1029+
// treat this identifier as if it were a source tree node by clearing the `Synthesized`
1030+
// flag and setting a parent node.
10401031
const react = createIdentifier(reactNamespace || "React");
10411032
react.flags &= ~NodeFlags.Synthesized;
10421033
react.parent = parent;

src/compiler/printer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ const _super = (function (geti, seti) {
281281
}
282282

283283
function printSourceFileWithExtendedDiagnostics(node: SourceFile) {
284-
performance.mark("printStart");
284+
const printStart = performance.mark();
285285
printSourceFile(node);
286-
performance.measure("printTime", "printStart");
286+
performance.measure("printTime", printStart);
287287
return node;
288288
}
289289

0 commit comments

Comments
 (0)