дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
perf(code-insight): read usage lines of many files in one call (#7598)
Usage lists read the line text of each file with one IPC call per file, which for ~1800 files took as long as the references request. fs_read_texts reads them in one call on a few threads (265-377 ms -> 57-59 ms on macOS); open editors and virtual documents keep using their editor text. Refs #6823
Цей коміт міститься в:
1 джерело
f39b728947
коміт
eace2fc741
5 files changed
+56
-15
No files matched your search
@@ -24,13 +24,36 @@ export async function readFileLines(path: string): Promise<string[] | null> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads several files with bounded concurrency; missing files map to `null`. */
|
||||
/**
|
||||
* Lines of several files; missing ones map to `null`. Files on disk come in one backend call:
|
||||
* a usage list can name thousands, and one call per file is slow where IPC is (WebView2).
|
||||
*/
|
||||
export async function readManyFileLines(
|
||||
paths: readonly string[],
|
||||
concurrency = 4,
|
||||
): Promise<Map<string, string[] | null>> {
|
||||
const out = new Map<string, string[] | null>();
|
||||
const queue = [...new Set(paths)];
|
||||
const queue: string[] = [];
|
||||
const onDisk: string[] = [];
|
||||
for (const p of new Set(paths)) {
|
||||
if (isTauri() && !editorsFor(p)[0] && !isVirtualUri(p)) onDisk.push(p);
|
||||
else queue.push(p);
|
||||
}
|
||||
if (onDisk.length > 1) {
|
||||
try {
|
||||
const texts = await call(commands.fsReadTexts(onDisk));
|
||||
onDisk.forEach((p, i) => {
|
||||
const text = texts[i];
|
||||
// Opened meanwhile: its editor has the newer text.
|
||||
out.set(
|
||||
p,
|
||||
editorsFor(p)[0] ? editorsFor(p)[0]!.view.state.doc.toJSON() : text == null ? null : text.split(/\r\n?|\n/),
|
||||
);
|
||||
});
|
||||
} catch {
|
||||
queue.push(...onDisk);
|
||||
}
|
||||
} else queue.push(...onDisk);
|
||||
const worker = async () => {
|
||||
for (let p = queue.shift(); p !== undefined; p = queue.shift()) {
|
||||
// oxlint-disable-next-line no-await-in-loop -- workers drain a shared queue; concurrency is bounded by the worker count
|
||||
|
||||
Reference in new issue
Заблокувати користувача