Conversation
…text revoke Agent-Logs-Url: https://github.com/Shougo/ddc.vim/sessions/817d4016-fb2c-4d65-a0a3-a2e2df20976a Co-authored-by: Shougo <41495+Shougo@users.noreply.github.com>
…eout Agent-Logs-Url: https://github.com/Shougo/ddc.vim/sessions/817d4016-fb2c-4d65-a0a3-a2e2df20976a Co-authored-by: Shougo <41495+Shougo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add improvements to autoCompleteDelay for CPU spike reduction
Improve autoCompleteDelay: per-buffer debounce + early callback cancellation
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rapid input with
autoCompleteDelay > 0caused CPU spikes becausecancelCompletion(and its hide/show UI overhead) was called on every keystroke, and the event lock was held for the entire delay duration blocking subsequent event processing.Changes
denops/ddc/types.ts/denops/ddc/context.tsbufNr: numbertoContext, populated from the already-fetchedworld.bufnr, to support per-buffer timer keying.denops/ddc/app.tsEarly callback revocation —
cbContext.revoke()is now called inonEventdispatcher before acquiring the lock. When new input arrives, any in-flight callback waits from the previous completion are cancelled immediately, letting the previous_onEventunblock and release the lock sooner.Per-buffer debounce timers — Replaces the single blocking
cancelCompletion+setTimeoutpattern with aMap<number, number>of per-buffer timers:cancelCompletionis called once, only when the timer fires (user paused typing), eliminating repeated hide/show cycles during rapid input._onEventcalls.autoCompleteDelay = 0behaviour is unchanged.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dl.deno.land/usr/bin/curl curl -s REDACTED(dns block)jsr.io/tmp/deno /tmp/deno check denops/ddc/types.ts denops/ddc/context.ts denops/ddc/app.ts(dns block)/tmp/deno /tmp/deno check --no-lock denops/ddc/types.ts(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
目的
変更内容(概要)
dispatcher.onEvent の受信直後に既存の CallbackContext を revoke して、外部コールバック待ち(createOnCallback を使っている処理)を即時キャンセルする。これにより、次の入力が来たときに以前の補完処理が callback 待ちで足止めされているケースを早期に解除できます。
autoCompleteDelay の実装を単一グローバルタイマーから per-buffer デバウンスタイマーに変更する。具体的には denops/ddc/app.ts にバッファ単位のタイマー管理 Map を追加し、複数バッファでの並行操作や干渉を避けます。
autoCompleteDelay が 0 の場合は既存挙動を保ち、オプション互換性を維持します。
タイマーが実際に発火したときに一度だけ ddc.cancelCompletion を呼んで補完をキャンセル → doCompletion を実行する方式に切り替え、素早い連続入力で cancelCompletion/hide の呼び出しが大量に発生するのを防ぎます。
対象ファイル
変更理由と逸失ケースの説明
既存実装では _onEvent 内で autoCompleteDelay > 0 のときに毎回 cancelCompletion を呼んでから setTimeout で待っていました。素早い継続入力時には cancelCompletion が大量呼び出され UI の hide/show や state 更新のオーバーヘッドが頻発し、CPU 使用率が急上昇します。
dispatcher.onEvent の実行フローでは新しいイベントが来ても既に走っている _onEvent が終了するまで待たされるため、createOnCallback 等で待機している処理が残ったままになりうる。そこで onEvent の入口で cbContext.revoke() を行うことで、外部コールバック待ち部分を早期に打ち切り、新しいイベント処理を速やかに始められるようにします。
設計の詳細(実装ポイント)
変数(denops/ddc/app.ts のファイルスコープ)
dispatcher.onEvent の変更
_onEvent 内の autoCompleteDelay 処理を置換
エラーハンドリング・互換性
差分草案(要約)
具体的なコードの抜粋(変更案、抜粋)
テスト/検証
既存の自動化ベンチ手順(headless nvim スクリプト)で、以下シナリオを比較します。
測定: nvim の CPU% ピーク、単一入力→補完までのレイテンシ(ログで計測)、cancelCompletion 呼び出し回数(ログ追加で計測)。期待: C が最も cancel 呼び出しを減らし CPU ピークが下がる。
PR の詳細
追加で行う作業(PR 後)
レビューの観点
以上の内容で PR を作成します。ブランチ名と PR タイトルで問題なければ実行します。
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Shougo/ddc.vim のパフォーマンスを改善したいです。特にユーザーが素早く入力したときに CPU 使用率が上がってしまう問題があります
Assistant: 続行するには先ほどのツール呼び出しの許可ダイアログで応答していただく必要があるため、ご返答をお待ちしています。
User: @copilot Accepted Confirmation: Are you sure?
Assistant: 結論(まずやるべきこと)
やることの流れ(短く)
今すぐ試せる緩和策(優先度高)
This pull request was created from Copilot chat.