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

@ -145,10 +145,9 @@
try {
// Wait for process environment being fully resolved
const perf = perfLib();
perf.mark('willWaitForShellEnv');
performance.mark('willWaitForShellEnv');
await whenEnvResolved;
perf.mark('didWaitForShellEnv');
performance.mark('didWaitForShellEnv');
// Callback only after process environment is resolved
const callbackResult = resultCallback(result, configuration);
@ -267,26 +266,8 @@
return window.vscode;
}
/**
* @return {{ mark: (name: string) => void }}
*/
function perfLib() {
globalThis.MonacoPerformanceMarks = globalThis.MonacoPerformanceMarks || [];
return {
/**
* @param {string} name
*/
mark(name) {
globalThis.MonacoPerformanceMarks.push(name, Date.now());
performance.mark(name);
}
};
}
return {
load,
globals,
perfLib
globals
};
}));

View file

@ -3,8 +3,7 @@
<html>
<head>
<script>
globalThis.MonacoPerformanceMarks = globalThis.MonacoPerformanceMarks || [];
globalThis.MonacoPerformanceMarks.push('renderer/started', Date.now());
performance.mark('renderer/started')
</script>
<meta charset="utf-8" />
@ -56,7 +55,7 @@
</script>
<script src="./static/out/vs/loader.js"></script>
<script>
globalThis.MonacoPerformanceMarks.push('willLoadWorkbenchMain', Date.now());
performance.mark('willLoadWorkbenchMain');
</script>
<script>
require(['vs/code/browser/workbench/workbench'], function() {});

View file

@ -3,8 +3,7 @@
<html>
<head>
<script>
globalThis.MonacoPerformanceMarks = globalThis.MonacoPerformanceMarks || [];
globalThis.MonacoPerformanceMarks.push('renderer/started', Date.now());
performance.mark('renderer/started')
</script>
<meta charset="utf-8" />
@ -55,7 +54,7 @@
</script>
<script src="./static/out/vs/loader.js"></script>
<script>
globalThis.MonacoPerformanceMarks.push('willLoadWorkbenchMain', Date.now());
performance.mark('willLoadWorkbenchMain');
</script>
<script src="./static/out/vs/workbench/workbench.web.api.nls.js"></script>
<script src="./static/out/vs/workbench/workbench.web.api.js"></script>

View file

@ -12,8 +12,7 @@
const bootstrapWindow = bootstrapWindowLib();
// Add a perf entry right from the top
const perf = bootstrapWindow.perfLib();
perf.mark('renderer/started');
performance.mark('renderer/started');
// Load workbench main JS, CSS and NLS all in parallel. This is an
// optimization to prevent a waterfall of loading to happen, because
@ -27,7 +26,7 @@
async function (workbench, configuration) {
// Mark start of workbench
perf.mark('didLoadWorkbenchMain');
performance.mark('didLoadWorkbenchMain');
// @ts-ignore
return require('vs/workbench/electron-browser/desktop.main').main(configuration);
@ -41,7 +40,7 @@
loaderConfig.recordStats = true;
},
beforeRequire: function () {
perf.mark('willLoadWorkbenchMain');
performance.mark('willLoadWorkbenchMain');
}
}
);
@ -52,8 +51,7 @@
/**
* @returns {{
* load: (modules: string[], resultCallback: (result, configuration: import('../../../platform/windows/common/windows').INativeWindowConfiguration) => any, options: object) => unknown,
* globals: () => typeof import('../../../base/parts/sandbox/electron-sandbox/globals'),
* perfLib: () => { mark: (name: string) => void }
* globals: () => typeof import('../../../base/parts/sandbox/electron-sandbox/globals')
* }}
*/
function bootstrapWindowLib() {
@ -72,7 +70,7 @@
* }} configuration
*/
function showPartsSplash(configuration) {
perf.mark('willShowPartsSplash');
performance.mark('willShowPartsSplash');
let data;
if (typeof configuration.partsSplashPath === 'string') {
@ -162,7 +160,7 @@
document.body.appendChild(splash);
}
perf.mark('didShowPartsSplash');
performance.mark('didShowPartsSplash');
}
//#endregion

View file

@ -12,8 +12,7 @@
const bootstrapWindow = bootstrapWindowLib();
// Add a perf entry right from the top
const perf = bootstrapWindow.perfLib();
perf.mark('renderer/started');
performance.mark('renderer/started');
// Load workbench main JS, CSS and NLS all in parallel. This is an
// optimization to prevent a waterfall of loading to happen, because
@ -27,7 +26,7 @@
async function (workbench, configuration) {
// Mark start of workbench
perf.mark('didLoadWorkbenchMain');
performance.mark('didLoadWorkbenchMain');
// @ts-ignore
return require('vs/workbench/electron-sandbox/desktop.main').main(configuration);
@ -41,7 +40,7 @@
loaderConfig.recordStats = true;
},
beforeRequire: function () {
perf.mark('willLoadWorkbenchMain');
performance.mark('willLoadWorkbenchMain');
}
}
);
@ -53,7 +52,6 @@
* @returns {{
* load: (modules: string[], resultCallback: (result, configuration: object) => any, options: object) => unknown,
* globals: () => typeof import('../../../base/parts/sandbox/electron-sandbox/globals'),
* perfLib: () => { mark: (name: string) => void }
* }}
*/
function bootstrapWindowLib() {

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);
}