diff --git a/src/vs/workbench/contrib/performance/electron-sandbox/startupTimings.ts b/src/vs/workbench/contrib/performance/electron-sandbox/startupTimings.ts index 684e9e0d6ecf5..5c853fccd6efa 100644 --- a/src/vs/workbench/contrib/performance/electron-sandbox/startupTimings.ts +++ b/src/vs/workbench/contrib/performance/electron-sandbox/startupTimings.ts @@ -23,6 +23,7 @@ import { IFileService } from 'vs/platform/files/common/files'; import { URI } from 'vs/base/common/uri'; import { VSBuffer } from 'vs/base/common/buffer'; import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust'; +import { IStorageService } from 'vs/platform/storage/common/storage'; export class StartupTimings implements IWorkbenchContribution { @@ -39,8 +40,8 @@ export class StartupTimings implements IWorkbenchContribution { @INativeWorkbenchEnvironmentService private readonly _environmentService: INativeWorkbenchEnvironmentService, @IProductService private readonly _productService: IProductService, @IWorkspaceTrustManagementService private readonly _workspaceTrustService: IWorkspaceTrustManagementService, + @IStorageService private readonly _storageService: IStorageService ) { - // this._report().catch(onUnexpectedError); } @@ -110,7 +111,7 @@ export class StartupTimings implements IWorkbenchContribution { if (activePanel) { return 'Current active panel : ' + this._panelService.getPanel(activePanel.getId())?.name; } - if (!didUseCachedData()) { + if (!didUseCachedData(this._productService, this._storageService, this._environmentService)) { return 'Either cache data is rejected or not created'; } if (!await this._updateService.isLatestVersion()) { diff --git a/src/vs/workbench/services/timer/electron-sandbox/timerService.ts b/src/vs/workbench/services/timer/electron-sandbox/timerService.ts index 3d71af649b456..ad7ac9c90ab8c 100644 --- a/src/vs/workbench/services/timer/electron-sandbox/timerService.ts +++ b/src/vs/workbench/services/timer/electron-sandbox/timerService.ts @@ -18,6 +18,9 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { process } from 'vs/base/parts/sandbox/electron-sandbox/globals'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService'; +import { isPreferringBrowserCodeLoad } from 'vs/base/common/platform'; +import { IProductService } from 'vs/platform/product/common/productService'; +import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; export class TimerService extends AbstractTimerService { @@ -33,7 +36,9 @@ export class TimerService extends AbstractTimerService { @IEditorService editorService: IEditorService, @IAccessibilityService accessibilityService: IAccessibilityService, @ITelemetryService telemetryService: ITelemetryService, - @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService + @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService, + @IProductService private readonly _productService: IProductService, + @IStorageService private readonly _storageService: IStorageService ) { super(lifecycleService, contextService, extensionService, updateService, viewletService, panelService, editorService, accessibilityService, telemetryService, layoutService); this.setPerformanceMarks('main', _environmentService.configuration.perfMarks); @@ -43,7 +48,7 @@ export class TimerService extends AbstractTimerService { return Boolean(this._environmentService.configuration.isInitialStartup); } protected _didUseCachedData(): boolean { - return didUseCachedData(); + return didUseCachedData(this._productService, this._storageService, this._environmentService); } protected _getWindowCount(): Promise { return this._nativeHostService.getWindowCount(); @@ -87,12 +92,28 @@ registerSingleton(ITimerService, TimerService); //#region cached data logic -export function didUseCachedData(): boolean { - // TODO@sandbox need a different way to figure out if cached data was used - if (process.sandboxed) { - return true; +const lastRunningCommitStorageKey = 'perf/lastRunningCommit'; +let _didUseCachedData: boolean | undefined = undefined; + +export function didUseCachedData(productService: IProductService, storageService: IStorageService, environmentService: INativeWorkbenchEnvironmentService): boolean { + // browser code loading: only a guess based on + // this being the first start with the commit + // or subsequent + if (isPreferringBrowserCodeLoad) { + if (typeof _didUseCachedData !== 'boolean') { + if (!environmentService.configuration.codeCachePath || !productService.commit) { + _didUseCachedData = false; // we only produce cached data whith commit and code cache path + } else if (storageService.get(lastRunningCommitStorageKey, StorageScope.GLOBAL) === productService.commit) { + _didUseCachedData = true; // subsequent start on same commit, assume cached data is there + } else { + storageService.store(lastRunningCommitStorageKey, productService.commit, StorageScope.GLOBAL, StorageTarget.MACHINE); + _didUseCachedData = false; // first time start on commit, assume cached data is not yet there + } + } + return _didUseCachedData; } - // We surely don't use cached data when we don't tell the loader to do so + // node.js code loading: We surely don't use cached data + // when we don't tell the loader to do so if (!Boolean((window).require.getConfig().nodeCachedData)) { return false; }