Skip to content

Commit

Permalink
Parallel resolve plugin entries
Browse files Browse the repository at this point in the history
Signed-off-by: Doron Nahari <[email protected]>
  • Loading branch information
DoroNahari committed Jan 28, 2020
1 parent 1ca3ec3 commit 3e14c58
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions packages/plugin-ext/src/main/node/plugin-deployer-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ import { injectable, optional, multiInject, inject } from 'inversify';
import {
PluginDeployerResolver, PluginDeployerFileHandler, PluginDeployerDirectoryHandler,
PluginDeployerEntry, PluginDeployer, PluginDeployerResolverInit, PluginDeployerFileHandlerContext,
PluginDeployerDirectoryHandlerContext, PluginDeployerEntryType, PluginDeployerHandler,
PluginDeployerDirectoryHandlerContext, PluginDeployerEntryType, PluginDeployerHandler
} from '../../common/plugin-protocol';
import { PluginDeployerEntryImpl } from './plugin-deployer-entry-impl';
import { PluginDeployerResolverContextImpl, PluginDeployerResolverInitImpl } from './plugin-deployer-resolver-context-impl';
import {
PluginDeployerResolverContextImpl,
PluginDeployerResolverInitImpl
} from './plugin-deployer-resolver-context-impl';
import { ProxyPluginDeployerEntry } from './plugin-deployer-proxy-entry-impl';
import { PluginDeployerFileHandlerContextImpl } from './plugin-deployer-file-handler-context-impl';
import { PluginDeployerDirectoryHandlerContextImpl } from './plugin-deployer-directory-handler-context-impl';
import { ILogger, Emitter } from '@theia/core';
import { PluginCliContribution } from './plugin-cli-contribution';
import { performance } from 'perf_hooks';

@injectable()
export class PluginDeployerImpl implements PluginDeployer {
Expand Down Expand Up @@ -100,27 +104,36 @@ export class PluginDeployerImpl implements PluginDeployer {
const pluginIdList = pluginsValue ? pluginsValue.split(',') : [];
const pluginsList = defaultPluginIdList.concat(pluginIdList).concat(defaultPluginsValueViaCli ? defaultPluginsValueViaCli.split(',') : []);

const startDeployTime = performance.now();
await this.deployMultipleEntries(pluginsList);

this.logMeasurement('Deploy plugins list', startDeployTime);
}

public async deploy(pluginEntry: string): Promise<void> {
const startDeployTime = performance.now();
await this.deployMultipleEntries([pluginEntry]);
this.logMeasurement('Deploy plugin entry', startDeployTime);
}

protected async deployMultipleEntries(pluginEntries: ReadonlyArray<string>): Promise<void> {
const visited = new Set<string>();
const pluginsToDeploy = new Map<string, PluginDeployerEntry>();

const queue = [...pluginEntries];
let queue = [...pluginEntries];
while (queue.length) {
const chunk = [];
const dependenciesChunk: Array< Map<string, string>> = [];
const workload: string[] = [];
while (queue.length) {
const current = queue.shift()!;
if (visited.has(current)) {
continue;
} else {
workload.push(current);
}
visited.add(current);
}
queue = [];
await Promise.all(workload.map(async current => {
try {
const pluginDeployerEntries = await this.resolvePlugin(current);
await this.applyFileHandlers(pluginDeployerEntries);
Expand All @@ -130,15 +143,15 @@ export class PluginDeployerImpl implements PluginDeployer {
if (dependencies && !pluginsToDeploy.has(dependencies.metadata.model.id)) {
pluginsToDeploy.set(dependencies.metadata.model.id, deployerEntry);
if (dependencies.mapping) {
chunk.push(dependencies.mapping);
dependenciesChunk.push(dependencies.mapping);
}
}
}
} catch (e) {
console.error(`Failed to resolve plugins from '${current}'`, e);
}
}
for (const dependencies of chunk) {
}));
for (const dependencies of dependenciesChunk) {
for (const [dependency, deployableDependency] of dependencies) {
if (!pluginsToDeploy.has(dependency)) {
queue.push(deployableDependency);
Expand Down Expand Up @@ -241,4 +254,8 @@ export class PluginDeployerImpl implements PluginDeployer {

return pluginDeployerEntries;
}

protected logMeasurement(prefix: string, startTime: number): void {
console.log(`${prefix} took: ${(performance.now() - startTime).toFixed(1)} ms`);
}
}

0 comments on commit 3e14c58

Please sign in to comment.