cancel usage of multi-thread to improve performance

This commit is contained in:
锦恢 2023-07-06 15:14:11 +08:00
parent 23ca078e73
commit 56d88b9c45
2 changed files with 19 additions and 8 deletions

View File

@ -18,14 +18,30 @@ const _hdlParser = {
} }
}; };
const debug = {
acquire: 0,
io: 0,
compute: 0
};
async function callParser(path, func) { async function callParser(path, func) {
const s1 = Date.now();
const wasmModule = await _hdlParser.acquire(); const wasmModule = await _hdlParser.acquire();
debug.acquire += Date.now() - s1;
const file = _hdlParser.tempPath; const file = _hdlParser.tempPath;
const fileLength = file.length; const fileLength = file.length;
const s2 = Date.now();
const source = fs.readFileSync(path, 'utf-8') + '\n'; const source = fs.readFileSync(path, 'utf-8') + '\n';
wasmModule.FS.writeFile(_hdlParser.tempPath, source, { encoding: 'utf8' }); wasmModule.FS.writeFile(_hdlParser.tempPath, source, { encoding: 'utf8' });
debug.io += Date.now() - s2;
const s3 = Date.now();
const res = wasmModule.ccall('call_parser', 'string', ['string', 'int', 'int'], [file, fileLength, func]); const res = wasmModule.ccall('call_parser', 'string', ['string', 'int', 'int'], [file, fileLength, func]);
debug.compute += Date.now() - s3;
console.log(debug);
return JSON.parse(res); return JSON.parse(res);
} }

View File

@ -239,13 +239,8 @@ class HdlParam {
} }
public async initHdlFiles(hdlFiles: AbsPath[] | Generator<AbsPath>) { public async initHdlFiles(hdlFiles: AbsPath[] | Generator<AbsPath>) {
const pools: Promise<void>[] = [];
for (const path of hdlFiles) { for (const path of hdlFiles) {
const p = this.doHdlFast(path); await this.doHdlFast(path);
pools.push(p);
}
for (const p of pools) {
await p;
} }
} }