diff --git a/src/hdlParser/core.ts b/src/hdlParser/core.ts index 902527e..9532cd0 100644 --- a/src/hdlParser/core.ts +++ b/src/hdlParser/core.ts @@ -1,4 +1,5 @@ import * as vscode from 'vscode'; +import * as os from 'os'; import { AbsPath, IProgress, opeParam } from '../global'; import { HdlLangID } from '../global/enum'; @@ -245,45 +246,42 @@ class HdlParam { const { t } = vscode.l10n; let count: number = 0; let fileNum = hdlFiles.length; - const parallelChunk = 5; + + // TODO: 找出最合理的核心数 + const parallelChunk = Math.min(os.cpus().length, 32); + console.log("use cpu: " + parallelChunk); + const pools: { id: number, promise: Promise, path: string }[] = []; const reportTitle = t('progress.build-module-tree'); progress?.report({ message: reportTitle + ` ${1}/${fileNum}`, increment: 0 }); + + async function consumePools() { + for (const p of pools) { + const increment = Math.floor(p.id / fileNum * 100); + await p.promise; + console.log("handle id " + p.id + ' increment: ' + increment); + progress?.report({ message: reportTitle + ` ${p.id}/${fileNum}`, increment }); + } + pools.length = 0; + } + for (const path of hdlFiles) { count ++; - await this.doHdlFast(path); - } - - // async function consumePools() { - // for (const p of pools) { - // const increment = Math.floor(p.id / fileNum * 100); - - // console.log('wait ' + p.path); - // await p.promise; - // console.log("handle id " + p.id + ' increment: ' + increment); - - // progress?.report({ message: reportTitle + ` ${p.id}/${fileNum}`, increment }); - // } - // pools.length = 0; - // } - - // for (const path of hdlFiles) { - // count ++; - // console.log('send request: ' + path); + console.log('send request: ' + path); - // const p = this.doHdlFast(path); - // pools.push({ id: count, promise: p, path }); - // if (pools.length % parallelChunk === 0) { - // // 消费并发池 - // await consumePools(); - // } - // } + const p = this.doHdlFast(path); + pools.push({ id: count, promise: p, path }); + if (pools.length % parallelChunk === 0) { + // 消费并发池 + await consumePools(); + } + } - // if (pools.length > 0) { - // await consumePools(); - // } + if (pools.length > 0) { + await consumePools(); + } } diff --git a/src/hdlParser/util.ts b/src/hdlParser/util.ts index a692468..e4ac909 100644 --- a/src/hdlParser/util.ts +++ b/src/hdlParser/util.ts @@ -11,10 +11,7 @@ async function doFastApi(path: string): Promise { const client = LspClient.MainClient; const langID = hdlFile.getLanguageId(path); if (client) { - console.log('send request ' + path); const response = await client.sendRequest(DoFastRequestType, { path }); - console.log('receive response ' + path); - response.languageId = langID; return response; }