Skip to content

Commit 04e6f9d

Browse files
committed
👍 Gradually update items in matcher to improve latency of Curator
1 parent d25c3e4 commit 04e6f9d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

denops/fall/event.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type Event =
3131
| { type: "collect-processor-succeeded" }
3232
| { type: "collect-processor-failed"; err: unknown }
3333
| { type: "match-processor-started" }
34+
| { type: "match-processor-updated" }
3435
| { type: "match-processor-succeeded" }
3536
| { type: "match-processor-failed"; err: unknown }
3637
| { type: "visualize-processor-started" }

denops/fall/picker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ export class Picker<T> implements AsyncDisposable {
348348
case "match-processor-started":
349349
this.#inputComponent.processing = true;
350350
break;
351+
case "match-processor-updated":
352+
this.#inputComponent.processed = this.#matchProcessor.items.length;
353+
this.#visualizeProcessor.start(denops, {
354+
items: this.#matchProcessor.items,
355+
});
356+
break;
351357
case "match-processor-succeeded":
352358
this.#inputComponent.processing = false;
353359
this.#inputComponent.processed = this.#matchProcessor.items.length;

denops/fall/processor/match.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ export class MatchProcessor<T> {
6767
: this.#filter.match(denops, { items, query }, { signal }),
6868
this.#threshold,
6969
);
70-
const matchedItems = [];
70+
// Gradually update items when `items` is empty to improve latency
71+
// of Curator.
72+
const matchedItems = items.length === 0
73+
? (this.#items = [], this.#items)
74+
: [];
7175
for await (const chunk of chunked(iter, this.#chunkSize)) {
7276
if (this.#paused) await this.#paused.promise;
7377
signal.throwIfAborted();
7478
matchedItems.push(...chunk);
79+
dispatch({ type: "match-processor-updated" });
7580
await delay(this.#interval, { signal });
7681
}
7782
this.#items = matchedItems;

0 commit comments

Comments
 (0)