Skip to content

Commit ad3c6ab

Browse files
committed
Add rudimentary allocation metrics
1 parent b85b172 commit ad3c6ab

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24157,27 +24157,39 @@ namespace ts {
2415724157
// signature, the subtype pass is useless. So skipping it is an optimization.
2415824158

2415924159
if (candidates.length > 1) {
24160+
const oldCounts = { nextSymbolId, nextNodeId, nextMergeId, nextFlowId };
2416024161
performance.mark("beforeChooseOverloadSubtype");
2416124162
result = chooseOverload(candidates, subtypeRelation, signatureHelpTrailingComma);
2416224163
performance.mark("afterChooseOverloadSubtype");
24164+
const newCounts = { nextSymbolId, nextNodeId, nextMergeId, nextFlowId };
2416324165
performance.measureOverload("beforeChooseOverloadSubtype", "afterChooseOverloadSubtype", {
2416424166
kind: "subtype",
2416524167
nodePos: nodePosToString(node),
2416624168
candidateCount: candidates.length,
2416724169
symbolName: getSymbolName(result || candidates[0]),
2416824170
succeeded: !!result,
24171+
symbolCount: newCounts.nextSymbolId - oldCounts.nextSymbolId,
24172+
nodeCount: newCounts.nextNodeId - oldCounts.nextNodeId,
24173+
mergeCount: newCounts.nextMergeId - oldCounts.nextMergeId,
24174+
flowCount: newCounts.nextFlowId - oldCounts.nextFlowId,
2416924175
});
2417024176
}
2417124177
if (!result) {
24178+
const oldCounts = { nextSymbolId, nextNodeId, nextMergeId, nextFlowId };
2417224179
performance.mark("beforeChooseOverloadAssignable");
2417324180
result = chooseOverload(candidates, assignableRelation, signatureHelpTrailingComma);
2417424181
performance.mark("afterChooseOverloadAssignable");
24182+
const newCounts = { nextSymbolId, nextNodeId, nextMergeId, nextFlowId };
2417524183
performance.measureOverload("beforeChooseOverloadAssignable", "afterChooseOverloadAssignable", {
2417624184
kind: "assignment",
2417724185
nodePos: nodePosToString(node),
2417824186
candidateCount: candidates.length,
2417924187
symbolName: getSymbolName(result || candidates[0]),
2418024188
succeeded: !!result,
24189+
symbolCount: newCounts.nextSymbolId - oldCounts.nextSymbolId,
24190+
nodeCount: newCounts.nextNodeId - oldCounts.nextNodeId,
24191+
mergeCount: newCounts.nextMergeId - oldCounts.nextMergeId,
24192+
flowCount: newCounts.nextFlowId - oldCounts.nextFlowId,
2418124193
});
2418224194
}
2418324195
if (result) {

src/compiler/performance.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ namespace ts.performance {
2626
nodePos: string,
2727
symbolName: string,
2828
succeeded: boolean,
29+
symbolCount: number,
30+
nodeCount: number,
31+
mergeCount: number,
32+
flowCount: number,
2933
}
3034

3135
export interface ChooseOverloadMeasure extends ChooseOverloadStats {

src/tsc/executeCommandLine.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,43 @@ namespace ts {
654654
candidateCount: measures[0].candidateCount,
655655
count: measures.length,
656656
timeMs: measures.map(m => m.timeMs).reduce((a, b) => a + b, 0),
657+
symbolCount: measures.map(m => m.symbolCount).reduce((a, b) => a + b, 0),
658+
nodeCount: measures.map(m => m.nodeCount).reduce((a, b) => a + b, 0),
659+
mergeCount: measures.map(m => m.mergeCount).reduce((a, b) => a + b, 0),
660+
flowCount: measures.map(m => m.flowCount).reduce((a, b) => a + b, 0),
657661
}));
658662

659-
const sortedOverloadStatistics = overloadStatistics.sort((a, b) => b.timeMs - a.timeMs);
660-
for (let i = 0; i < 10 && i < sortedOverloadStatistics.length; i++) {
661-
const stat = sortedOverloadStatistics[i];
662-
// sys.write(`${stat.symbolName}: ${stat.timeMs}ms (count = ${stat.count}) ${sys.newLine}`);
663+
const topCount = 5;
664+
665+
sys.write("Top " + topCount + " by time" + sys.newLine);
666+
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.timeMs - a.timeMs))) {
667+
sys.write(JSON.stringify(stat) + sys.newLine);
668+
}
669+
sys.write(sys.newLine);
670+
671+
sys.write("Top " + topCount + " by symbols" + sys.newLine);
672+
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.symbolCount - a.symbolCount))) {
663673
sys.write(JSON.stringify(stat) + sys.newLine);
664674
}
675+
sys.write(sys.newLine);
676+
677+
sys.write("Top " + topCount + " by nodes" + sys.newLine);
678+
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.nodeCount - a.nodeCount))) {
679+
sys.write(JSON.stringify(stat) + sys.newLine);
680+
}
681+
sys.write(sys.newLine);
682+
683+
sys.write("Top " + topCount + " by merges" + sys.newLine);
684+
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.mergeCount - a.mergeCount))) {
685+
sys.write(JSON.stringify(stat) + sys.newLine);
686+
}
687+
sys.write(sys.newLine);
688+
689+
sys.write("Top " + topCount + " by flows" + sys.newLine);
690+
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.flowCount - a.flowCount))) {
691+
sys.write(JSON.stringify(stat) + sys.newLine);
692+
}
693+
sys.write(sys.newLine);
665694
}
666695
else {
667696
// Individual component times.
@@ -681,6 +710,10 @@ namespace ts {
681710
performance.disable();
682711
}
683712

713+
function takeAtMost<T>(count: number, array: readonly T[]): readonly T[] {
714+
return array.slice(0, Math.min(array.length, count));
715+
}
716+
684717
function reportStatistics() {
685718
let nameSize = 0;
686719
let valueSize = 0;

0 commit comments

Comments
 (0)