Skip to content

Commit 934910e

Browse files
authored
Merge pull request #33 from vim-fall/fix-for-slow-source
feat: Add chunk interval to collect and match processors
2 parents fc8d57d + 92a38fb commit 934910e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

denops/fall/processor/collect.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import { dispatch } from "../event.ts";
99

1010
const THRESHOLD = 10000;
1111
const CHUNK_SIZE = 1000;
12+
const CHUNK_INTERVAL = 100;
1213

1314
export type CollectProcessorOptions = {
1415
threshold?: number;
1516
chunkSize?: number;
17+
chunkInterval?: number;
1618
};
1719

1820
export class CollectProcessor<T extends Detail> implements Disposable {
@@ -21,6 +23,7 @@ export class CollectProcessor<T extends Detail> implements Disposable {
2123
readonly #source: Source<T>;
2224
readonly #threshold: number;
2325
readonly #chunkSize: number;
26+
readonly #chunkInterval: number;
2427
#processing?: Promise<void>;
2528
#paused?: PromiseWithResolvers<void>;
2629

@@ -31,6 +34,7 @@ export class CollectProcessor<T extends Detail> implements Disposable {
3134
this.#source = source;
3235
this.#threshold = options.threshold ?? THRESHOLD;
3336
this.#chunkSize = options.chunkSize ?? CHUNK_SIZE;
37+
this.#chunkInterval = options.chunkInterval ?? CHUNK_INTERVAL;
3438
}
3539

3640
get items() {
@@ -72,10 +76,15 @@ export class CollectProcessor<T extends Detail> implements Disposable {
7276
dispatch({ type: "collect-processor-updated" });
7377
};
7478
const chunker = new Chunker<IdItem<T>>(this.#chunkSize);
79+
let lastChunkTime = performance.now();
7580
for await (const item of iter) {
7681
if (this.#paused) await this.#paused.promise;
7782
signal.throwIfAborted();
78-
if (chunker.put(item)) {
83+
if (
84+
chunker.put(item) ||
85+
performance.now() - lastChunkTime > this.#chunkInterval
86+
) {
87+
lastChunkTime = performance.now();
7988
update(chunker.consume());
8089
}
8190
}

denops/fall/processor/match.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import { dispatch } from "../event.ts";
1111
const INTERVAL = 0;
1212
const THRESHOLD = 10000;
1313
const CHUNK_SIZE = 1000;
14+
const CHUNK_INTERVAL = 100;
1415

1516
export type MatchProcessorOptions = {
1617
interval?: number;
1718
threshold?: number;
1819
chunkSize?: number;
20+
chunkInterval?: number;
1921
incremental?: boolean;
2022
};
2123

@@ -24,6 +26,7 @@ export class MatchProcessor<T extends Detail> implements Disposable {
2426
readonly #interval: number;
2527
readonly #threshold: number;
2628
readonly #chunkSize: number;
29+
readonly #chunkInterval: number;
2730
readonly #incremental: boolean;
2831
#controller: AbortController = new AbortController();
2932
#processing?: Promise<void>;
@@ -38,6 +41,7 @@ export class MatchProcessor<T extends Detail> implements Disposable {
3841
this.#interval = options.interval ?? INTERVAL;
3942
this.#threshold = options.threshold ?? THRESHOLD;
4043
this.#chunkSize = options.chunkSize ?? CHUNK_SIZE;
44+
this.#chunkInterval = options.chunkInterval ?? CHUNK_INTERVAL;
4145
this.#incremental = options.incremental ?? false;
4246
}
4347

@@ -109,9 +113,14 @@ export class MatchProcessor<T extends Detail> implements Disposable {
109113
}
110114
};
111115
const chunker = new Chunker<IdItem<T>>(this.#chunkSize);
116+
let lastChunkTime = performance.now();
112117
for await (const item of iter) {
113118
signal.throwIfAborted();
114-
if (chunker.put(item)) {
119+
if (
120+
chunker.put(item) ||
121+
performance.now() - lastChunkTime > this.#chunkInterval
122+
) {
123+
lastChunkTime = performance.now();
115124
update(chunker.consume());
116125
await delay(this.#interval, { signal });
117126
}

0 commit comments

Comments
 (0)