修改线程调度逻辑
This commit is contained in:
parent
1db2ff4986
commit
d2755e0a05
@ -1,4 +1,5 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import * as os from 'os';
|
||||||
|
|
||||||
import { AbsPath, IProgress, opeParam } from '../global';
|
import { AbsPath, IProgress, opeParam } from '../global';
|
||||||
import { HdlLangID } from '../global/enum';
|
import { HdlLangID } from '../global/enum';
|
||||||
@ -245,45 +246,42 @@ class HdlParam {
|
|||||||
const { t } = vscode.l10n;
|
const { t } = vscode.l10n;
|
||||||
let count: number = 0;
|
let count: number = 0;
|
||||||
let fileNum = hdlFiles.length;
|
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<void>, path: string }[] = [];
|
const pools: { id: number, promise: Promise<void>, path: string }[] = [];
|
||||||
const reportTitle = t('progress.build-module-tree');
|
const reportTitle = t('progress.build-module-tree');
|
||||||
|
|
||||||
progress?.report({ message: reportTitle + ` ${1}/${fileNum}`, increment: 0 });
|
progress?.report({ message: reportTitle + ` ${1}/${fileNum}`, increment: 0 });
|
||||||
for (const path of hdlFiles) {
|
|
||||||
count ++;
|
async function consumePools() {
|
||||||
await this.doHdlFast(path);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function consumePools() {
|
for (const path of hdlFiles) {
|
||||||
// for (const p of pools) {
|
count ++;
|
||||||
// const increment = Math.floor(p.id / fileNum * 100);
|
console.log('send request: ' + path);
|
||||||
|
|
||||||
// console.log('wait ' + p.path);
|
const p = this.doHdlFast(path);
|
||||||
// await p.promise;
|
pools.push({ id: count, promise: p, path });
|
||||||
// console.log("handle id " + p.id + ' increment: ' + increment);
|
if (pools.length % parallelChunk === 0) {
|
||||||
|
// 消费并发池
|
||||||
|
await consumePools();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// progress?.report({ message: reportTitle + ` ${p.id}/${fileNum}`, increment });
|
if (pools.length > 0) {
|
||||||
// }
|
await consumePools();
|
||||||
// pools.length = 0;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// for (const path of hdlFiles) {
|
|
||||||
// count ++;
|
|
||||||
// console.log('send request: ' + path);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,7 @@ async function doFastApi(path: string): Promise<Fast | undefined> {
|
|||||||
const client = LspClient.MainClient;
|
const client = LspClient.MainClient;
|
||||||
const langID = hdlFile.getLanguageId(path);
|
const langID = hdlFile.getLanguageId(path);
|
||||||
if (client) {
|
if (client) {
|
||||||
console.log('send request ' + path);
|
|
||||||
const response = await client.sendRequest(DoFastRequestType, { path });
|
const response = await client.sendRequest(DoFastRequestType, { path });
|
||||||
console.log('receive response ' + path);
|
|
||||||
|
|
||||||
response.languageId = langID;
|
response.languageId = langID;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user