Enable concurrent execution for parallel-safe matchers#158
Merged
Conversation
…her execution Co-authored-by: Shougo <41495+Shougo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add matcherConcurrency option for parallel execution of matchers
Enable concurrent execution for parallel-safe matchers
Mar 13, 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.
Adds a
matcherConcurrencyoption that allows matchers to run concurrently across item chunks, with automatic fallback to sequential execution when safety conditions aren't met. Default is1(fully backward compatible).New option
matcherConcurrency: number(default:1) — maximum number of concurrent chunks when running matchers.Filter opt-in:
static parallelSafeBaseFiltergains astatic parallelSafe = falseclass property. Filters declare themselves safe by overriding it:Parallel execution logic (
#runMatchersConcurrently)Parallel execution activates only when all hold:
matcherConcurrency > 1static parallelSafe = trueItems are split into
⌈N/concurrency⌉-sized chunks;callFiltersruns on each viaPromise.all, results are concatenated in order. Sorters always run sequentially on the full result.Falls back transparently to sequential
callFilterson: opt-out filter, item count mismatch, any exception, or stalerunId(a newer concurrent run superseded this one).Stale-result guard
#latestMatcherRunIdis incremented per invocation. AfterPromise.allresolves, if the counter has advanced (a newer run started during the await), results are discarded and sequential fallback is used.Files changed
types.ts—matcherConcurrency: numberadded toDduOptionscontext.ts— defaultmatcherConcurrency: 1; two new unit testsbase/filter.ts—static parallelSafe = falseonBaseFilterddu.ts—#latestMatcherRunIdfield;#runMatchersConcurrently()method;#filterItemscall site split into matchers (concurrent) + sorters (sequential)doc/ddu.txt—matcherConcurrencyoption andparallelSafeattribute documentedOriginal prompt
目的
shougo/ddu.vim の matcher フェーズを安全に並列化できるように、core 側に並列化スキャフォールドを追加するPRを作成してください。今回の変更は並列化を強制的に有効化するものではなく、各 filter が自己申告する安全フラグ (static parallelSafe) を尊重した上で、チャンク単位で matchers を並列実行し、整合性検証(チャンク内でアイテムが削除されていないこと等)に失敗した場合は安全に逐次処理へフォールバックする仕組みを導入することが目的です。さらに、古い並列ジョブの結果適用を防ぐ runId/cancellation トークンを導入して入力変更時の競合を回避します。
要求仕様(実装要件)
変更の範囲(実装対象ファイル/場所の提案)
作業要領
テスト実行手順(レビューワ向け)
注意: リポジトリや他のコードベースの細かな構造(options の定義ファイルや callFilters の正確なシグネチャ)に依存するため、実装時に該当箇所の細かい調整を行い、CI と型チェックを通す必要があります。実装はまず feature/matchers-concurrency ブランチに最小パッチを作成し、CI で問題なければ拡張を続けてください。
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: 他の source の実装も確認しました。file_external はセットしていました。file_rec はセットしてなかったので追加しました。これで問題ないでしょう
Assistant: 良い対応です — file_rec にも
status.timeをセットしたなら、sorter_mtime 側で余分なDeno.statが走るケースはほぼ無くなるはずです。短く確認事項と念のためのチェックリスト、次にやると良いことをまとめます。最低限の確認(すぐやる)
性能確認(ベンチ)
this.#options.profile = trueにしてログを取ると楽です。念のためチェックするエッジケース
改善案(任意)
まとめ
status.timeを入れた対応で問題ない見込みです。上の最低限の確認(手動動作 + 型チェック + ベンチ)をやって問題がなければクローズで大丈夫です。User: >並列化・制御付き並行処理(高効果だが慎重に)
やってみたいけれど危険性もありますね。これは専用ブランチを切って慎重にいきたいところ。
This pull request was created from Copilot chat.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.