Skip to content

perf: optimize completion path across all layers#247

Open
Shougo with Copilot wants to merge 2 commits into
mainfrom
copilot/research-skkeleton-optimization
Open

perf: optimize completion path across all layers#247
Shougo with Copilot wants to merge 2 commits into
mainfrom
copilot/research-skkeleton-optimization

Conversation

Copilot AI commented May 8, 2026

Copy link
Copy Markdown

Summary

前回の分析で特定した補完パス全体のボトルネックを一括で修正します。

Changes

user_dictionary.tsgetRanks の O(N) スキャン除去(改善案 C + I)

  • 従来: 全候補を Set に収め、#rank の全エントリ (entries() → 配列展開 → filter) をスキャン
  • 新実装: キャッシュ済み候補を直接イテレートして #rank.get(c) で O(1) ルックアップ
  • 同一候補が複数エントリに現れた場合の重複も Set で排除

deno_kv.ts#searchByPrefix の get + list 並列化(改善案 E)

  • db.get()(完全一致)と db.list()(前方一致)は独立クエリ
  • Promise.all で並列発行し、レイテンシを約半分に削減

main.ts — 統合ディスパッチャ追加(改善案 A + G)

  • getCompletionResultWithRanks: getCompletionResultgetRanks を 1 RPC に集約
  • getCandidatesBatch: N 個の見出しをまとめて照会し 1 RPC に集約(skk_server の単一 readCallback との互換性維持のため内部は逐次)

@ddc-sources/skkeleton/main.ts — RPC 2往復 → 1往復(改善案 A + B)

  • gather()getCompletionResultWithRanks 単一呼び出しに変更
  • candidates.sort(…localeCompare…) は直後の rank ソートで上書きされる重複であったため除去

@ddc-sources/skkeleton_okuri/main.ts — N 回 dispatch → 1 回(改善案 G)

  • okuriSplits で得た全 midashi を getCandidatesBatch で一括照会

@ddc-sources/skkeleton_okuri/okurisplits.ts — 可読性改善(改善案 H)

  • Array.from(Array(n), …) + map を単純な for ループに置換(動作等価)

Backward Compatibility

  • 既存ディスパッチャ (getCompletionResult, getRanks, getCandidates) は全て残存。外部プラグインとの互換性を維持。

@Shougo
Shougo marked this pull request as ready for review May 8, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants