Skip to content

Commit 08d0aa5

Browse files
committed
store marks and measurements flat, only create objects when needed
1 parent 0cb6309 commit 08d0aa5

3 files changed

Lines changed: 43 additions & 38 deletions

File tree

src/vs/base/common/performance.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export function time(name: string): { stop(): void };
2121
/**
2222
* All entries filtered by type and sorted by `startTime`.
2323
*/
24-
export function getEntries(type?: 'mark' | 'measure'): PerformanceEntry[];
24+
export function getEntries(type: 'mark' | 'measure'): PerformanceEntry[];
2525

26-
/**
27-
* Import entries
28-
*/
29-
export function importEntries(entries: PerformanceEntry[]): void;
26+
27+
type ExportData = any[];
28+
export function importEntries(data: ExportData): void;
29+
export function exportEntries(): ExportData;

src/vs/base/common/performance.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// This module can be loaded in an amd and commonjs-context.
1111
// Because we want both instances to use the same perf-data
1212
// we store them globally
13+
// stores data as 'type','name','startTime','duration'
1314
global._performanceEntries = global._performanceEntries || [];
1415

1516
if (typeof define !== "function" && typeof module === "object" && typeof module.exports === "object") {
@@ -25,42 +26,35 @@ define([], function () {
2526
// const _now = global.performance && performance.now ? performance.now : Date.now
2627
const _now = Date.now;
2728

28-
class PerformanceEntry {
29-
constructor(type, name, startTime, duration) {
30-
this.type = type;
31-
this.name = name;
32-
this.startTime = startTime;
33-
this.duration = duration;
34-
}
29+
function importEntries(entries) {
30+
global._performanceEntries.splice(0, 0, ...entries);
3531
}
3632

37-
function _getEntry(type, name) {
38-
for (let i = global._performanceEntries.length - 1; i >= 0; i--) {
39-
if (
40-
(type === undefined || global._performanceEntries[i].type === type) &&
41-
(name === undefined || global._performanceEntries[i].name === name)
42-
) {
43-
return global._performanceEntries[i];
44-
}
45-
}
33+
function exportEntries() {
34+
return global._performanceEntries.splice(0);
4635
}
4736

48-
function importEntries(entries) {
49-
global._performanceEntries.splice(0, 0, ...entries);
50-
}
37+
function getEntries(type) {
38+
const result = [];
39+
const entries = global._performanceEntries;
40+
for (let i = 0; i < entries.length; i += 4) {
41+
if (entries[i] === type) {
42+
result.push({
43+
type: entries[i],
44+
name: entries[i + 1],
45+
startTime: entries[i + 2],
46+
duration: entries[i + 3],
47+
});
48+
}
49+
}
5150

52-
function getEntries(type, name) {
53-
return global._performanceEntries.filter(entry => {
54-
return (type === undefined || entry.type === type) &&
55-
(name === undefined || entry.name === name);
56-
}).sort((a, b) => {
51+
return result.sort((a, b) => {
5752
return a.startTime - b.startTime;
5853
});
5954
}
6055

6156
function mark(name) {
62-
const entry = new PerformanceEntry('mark', name, _now(), 0);
63-
global._performanceEntries.push(entry);
57+
global._performanceEntries.push('mark', name, _now(), 0);
6458
if (typeof console.timeStamp === 'function') {
6559
console.timeStamp(name);
6660
}
@@ -81,25 +75,36 @@ define([], function () {
8175
if (!from) {
8276
startTime = now;
8377
} else {
84-
startTime = _getEntry(undefined, from).startTime;
78+
startTime = _getLastStartTime(from);
8579
}
8680

8781
if (!to) {
8882
duration = now - startTime;
8983
} else {
90-
duration = _getEntry(undefined, to).startTime - startTime;
84+
duration = _getLastStartTime(to) - startTime;
85+
}
86+
87+
global._performanceEntries.push('measure', name, startTime, duration);
88+
}
89+
90+
function _getLastStartTime(name) {
91+
const entries = global._performanceEntries;
92+
for (let i = entries.length - 1; i >= 0; i -= 4) {
93+
if (entries[i - 2] === name) {
94+
return entries[i - 1];
95+
}
9196
}
9297

93-
const entry = new PerformanceEntry('measure', name, startTime, duration);
94-
global._performanceEntries.push(entry);
98+
throw new Error(name + ' not found');
9599
}
96100

97101
var exports = {
98102
mark: mark,
99103
measure: measure,
100104
time: time,
101105
getEntries: getEntries,
102-
importEntries: importEntries
106+
importEntries: importEntries,
107+
exportEntries: exportEntries
103108
};
104109

105110
return exports;

src/vs/code/electron-main/window.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { ICodeWindow } from 'vs/platform/windows/electron-main/windows';
2626
import { IWorkspaceIdentifier, IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces';
2727
import { IBackupMainService } from 'vs/platform/backup/common/backup';
2828
import { ICommandAction } from 'vs/platform/actions/common/actions';
29-
import { mark, getEntries } from 'vs/base/common/performance';
29+
import { mark, exportEntries } from 'vs/base/common/performance';
3030

3131
export interface IWindowState {
3232
width?: number;
@@ -580,7 +580,7 @@ export class CodeWindow implements ICodeWindow {
580580
windowConfiguration.backgroundColor = this.getBackgroundColor();
581581

582582
// Perf Counters
583-
windowConfiguration.perfEntries = getEntries();
583+
windowConfiguration.perfEntries = exportEntries();
584584
windowConfiguration.perfStartTime = global.perfStartTime;
585585
windowConfiguration.perfAppReady = global.perfAppReady;
586586
windowConfiguration.perfWindowLoadTime = Date.now();

0 commit comments

Comments
 (0)