Skip to content

Commit

Permalink
Improve extension activation time (microsoft#2439)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwateratmsft authored and Dmarch28 committed Mar 4, 2021
1 parent 84338aa commit 9c79a5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 11 additions & 11 deletions src/docker/ContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ export class DockerContextManager implements ContextManager, Disposable {
if (isNewContextType(currentContext.Type)) {
// Currently vscode-docker:aciContext vscode-docker:newSdkContext mean the same thing
// But that probably won't be true in the future, so define both as separate concepts now
await this.setVsCodeContext('vscode-docker:aciContext', true);
await this.setVsCodeContext('vscode-docker:newSdkContext', true);
this.setVsCodeContext('vscode-docker:aciContext', true);
this.setVsCodeContext('vscode-docker:newSdkContext', true);

const dsc = await import('./DockerServeClient/DockerServeClient');
ext.dockerClient = new dsc.DockerServeClient(currentContext);
} else {
await this.setVsCodeContext('vscode-docker:aciContext', false);
await this.setVsCodeContext('vscode-docker:newSdkContext', false);
this.setVsCodeContext('vscode-docker:aciContext', false);
this.setVsCodeContext('vscode-docker:newSdkContext', false);

const dockerode = await import('./DockerodeApiClient/DockerodeApiClient');
ext.dockerClient = new dockerode.DockerodeApiClient(currentContext);
Expand Down Expand Up @@ -193,7 +193,7 @@ export class DockerContextManager implements ContextManager, Disposable {
actionContext.telemetry.properties.hostSource = 'docker.context';
} else if ((dockerContextEnv = process.env.DOCKER_CONTEXT)) { // Assignment + check is intentional
actionContext.telemetry.properties.hostSource = 'envContext';
} else if (!(await fse.pathExists(dockerContextsFolder)) || (await fse.readdir(dockerContextsFolder)).length === 0) {
} else if (!fse.pathExistsSync(dockerContextsFolder) || fse.readdirSync(dockerContextsFolder).length === 0) { // Sync is intentionally used for performance, this is on the activation code path
// If there's nothing inside ~/.docker/contexts/meta, then there's only the default, unmodifiable DOCKER_HOST-based context
// It is unnecessary to call `docker context inspect`
actionContext.telemetry.properties.hostSource = 'defaultContextOnly';
Expand All @@ -204,7 +204,7 @@ export class DockerContextManager implements ContextManager, Disposable {

if (dockerHostEnv !== undefined) {
actionContext.telemetry.properties.hostProtocol = new URL(dockerHostEnv).protocol;
await this.setVsCodeContext('vscode-docker:contextLocked', true);
this.setVsCodeContext('vscode-docker:contextLocked', true);

return [{
...defaultContext,
Expand Down Expand Up @@ -254,9 +254,9 @@ export class DockerContextManager implements ContextManager, Disposable {
}

if (dockerContextEnv) {
await this.setVsCodeContext('vscode-docker:contextLocked', true);
this.setVsCodeContext('vscode-docker:contextLocked', true);
} else {
await this.setVsCodeContext('vscode-docker:contextLocked', false);
this.setVsCodeContext('vscode-docker:contextLocked', false);
}

return result;
Expand Down Expand Up @@ -294,12 +294,12 @@ export class DockerContextManager implements ContextManager, Disposable {
}

// Set the VSCode context to the result (which may expose commands, etc.)
await this.setVsCodeContext('vscode-docker:newCliPresent', result);
this.setVsCodeContext('vscode-docker:newCliPresent', result);
return result;
} catch { } // Best effort
}

private async setVsCodeContext(vsCodeContext: VSCodeContext, value: boolean): Promise<void> {
return commands.executeCommand('setContext', vsCodeContext, value);
private setVsCodeContext(vsCodeContext: VSCodeContext, value: boolean): void {
void commands.executeCommand('setContext', vsCodeContext, value);
}
}
8 changes: 3 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import * as fse from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
Expand Down Expand Up @@ -31,7 +30,6 @@ import { AzureAccountExtensionListener } from './utils/AzureAccountExtensionList
import { cryptoUtils } from './utils/cryptoUtils';
import { Keytar } from './utils/keytar';
import { isLinux, isMac, isWindows } from './utils/osUtils';
import { bufferToString } from './utils/spawnAsync';

export type KeyInfo = { [keyName: string]: string };

Expand Down Expand Up @@ -162,8 +160,9 @@ async function getDockerInstallationIDHash(): Promise<string> {
installIdFilePath = path.join(os.homedir(), 'Library', 'Group Containers', 'group.com.docker', 'userId');
}

if (installIdFilePath && await fse.pathExists(installIdFilePath)) {
let result = bufferToString(await fse.readFile(installIdFilePath));
// Sync is intentionally used for performance, this is on the activation code path
if (installIdFilePath && fse.pathExistsSync(installIdFilePath)) {
let result = fse.readFileSync(installIdFilePath, 'utf-8');
result = cryptoUtils.hashString(result);
await ext.context.globalState.update('docker.installIdHash', result);
return result;
Expand Down Expand Up @@ -250,7 +249,6 @@ function activateLanguageClient(ctx: vscode.ExtensionContext): void {
"server.js"
)
);
assert(true === await fse.pathExists(serverModule), "Could not find language client module");

let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };

Expand Down

0 comments on commit 9c79a5f

Please sign in to comment.