remove direct writes to globalThis.MonacoPerformanceMarks, use native performance instead, import native performance entries into timer service, fyi @bpasero

This commit is contained in:
Johannes Rieken
2020-12-14 11:12:23 +01:00
parent 4b88174158
commit ec5da6d09c
6 changed files with 44 additions and 43 deletions

View File

@@ -356,7 +356,7 @@ class PerfMarks {
if (!toEntry) {
return 0;
}
return toEntry.startTime - fromEntry.startTime;
return Math.round(toEntry.startTime - fromEntry.startTime);
}
@@ -396,7 +396,15 @@ export abstract class AbstractTimerService implements ITimerService {
this._extensionService.whenInstalledExtensionsRegistered(),
_lifecycleService.when(LifecyclePhase.Restored)
]).then(() => {
this.submitPerformanceMarks(perf.getMarks());
// import native-browser marks
this._submitNativeMarks();
// because "our" perf.mark-util also adds native performance marks
// no extra import of "our" marks is needed, they are already imported
// by importing native perf marks (see above)
// this.submitPerformanceMarks(perf.getMarks());
return this._computeStartupMetrics();
}).then(metrics => {
this._reportStartupTimes(metrics);
@@ -404,6 +412,24 @@ export abstract class AbstractTimerService implements ITimerService {
});
}
private _submitNativeMarks(): void {
let timeOrigin = performance.timeOrigin;
if (!timeOrigin) {
// polyfill for Safari
const entry = performance.timing;
timeOrigin = entry.navigationStart || entry.redirectStart || entry.fetchStart;
}
const marks: perf.PerformanceMark[] = performance.getEntriesByType('mark').map(entry => {
return {
name: entry.name,
startTime: timeOrigin + entry.startTime
};
});
this.submitPerformanceMarks(marks);
}
submitPerformanceMarks(marks: perf.PerformanceMark[]): void {
this._marks.submitMarks(marks);
}