Skip to content

Commit

Permalink
sandbox - implement didUseCachedData when node.js code loading is d…
Browse files Browse the repository at this point in the history
…isabled (#98682)
  • Loading branch information
bpasero committed Jun 8, 2021
1 parent 0967708 commit 745e354
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}

Expand Down Expand Up @@ -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()) {
Expand Down
35 changes: 28 additions & 7 deletions src/vs/workbench/services/timer/electron-sandbox/timerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
Expand All @@ -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<number> {
return this._nativeHostService.getWindowCount();
Expand Down Expand Up @@ -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((<any>window).require.getConfig().nodeCachedData)) {
return false;
}
Expand Down

0 comments on commit 745e354

Please sign in to comment.