Conversation
…ps/ddx Co-authored-by: Shougo <41495+Shougo@users.noreply.github.com> Agent-Logs-Url: https://github.com/Shougo/ddx.vim/sessions/bac8e703-2e65-40df-94d7-0f95e1f42970
Copilot
AI
changed the title
[WIP] Optimize performance by caching imports and removing unnecessary awaits
perf: remove unnecessary Mar 24, 2026
return await and cache import maps in denops/ddx
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.
Two micro-optimisations ported from Shougo/dpp.vim#37 to reduce redundant microtasks and redundant filesystem I/O on every plugin import.
Remove unnecessary
return awaitSimple tail-call delegations that were needlessly suspending with
await:Only pure delegations changed;
awaitinsidetry/catchblocks is left intact to preserve stack traces.Cache import maps and importers (
utils.ts)Two module-scope caches keyed by parent directory:
tryLoadImportMapnow hitsimportMapCachebefore touching the filesystem; storesnullfor directories with no import map so the four-pattern probe is skipped on repeat calls.importPluginreuses a cachedImportMapImporterinstance instead of constructing a new one per call; also drops the now-redundantawaitbeforeimporter.import()/import().Trade-off: import map changes during the process lifetime are not picked up (same as dpp.vim#37).
Original prompt
Two small performance improvements adapted from Shougo/dpp.vim PR #37: remove unnecessary
return awaitand cache import maps/ImportMapImporter at module scope to avoid redundant I/O and instance allocation.Summary of changes to apply in Shougo/ddx.vim (denops parts):
return awaitreturn await someAsync()(and are not inside try/catch used to capture stack) withreturn someAsync()to avoid an extra microtask. Only change occurrences that are simple delegations; do not change code whereawaitis used inside try/catch to preserve stack behaviour.const importMapCache = new Map<string, ImportMap | null>();const importerCache = new Map<string, ImportMapImporter>();tryLoadImportMap(script: string)to checkimportMapCachekeyed by parent directory before reading files. Storenullfor directories without import maps.importPlugin(path: string)to reuse cachedImportMapImporterinstances fromimporterCachewhen an import map exists for the path's parent directory.Files to change (identified during repository scan):
return awaitwrappers where safe)Commit strategy:
return awaitonly.Testing and validation:
deno test -A --doc --parallel --shuffle denops/**/*.ts.PR title suggestion:
perf: remove unnecessary
return awaitand cache import maps in denops/ddxNotes:
awaitusages untouched to preserve stack traces.Please run CI/tests and review; I can follow up with fixes if any issues are found.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Shougo/dpp.vim#37
こちらと同様の修正を ddu.vim, ddc.vim, ddx.vim, ddt.vim に適用させることは可能ですか。
Assistant: 確認して、dpp.vim の PR #37 の内容を取得します。変更点を見て、同じ修正を ddu.vim, ddc.vim, ddx.vim, ddt.vim に適用するための差分を作成します。まず PR の内容を読み取ります。
Assistant: はい、可能です。やるべき変更は dpp.vim の PR #37 と同じで、主に次の2点です。
return awaitの削除(マイクロタスクの削減)tryLoadImportMap/importPluginでの import map と ImportMapImporter のキャッシュ)やり方と現状の確認(私が行ったこと)
PR #37 の内容を確認しました(perf: remove unnecessary
return awaitand cache import maps in denops/dpp)。ddu.vim / ddc.vim / ddx.vim / ddt.vim のソースを走査して、
return awaitと import-map 処理の該当箇所を探しました。該当ファイルの候補は以下です。uiVisible/uiWinids/uiUpdateCursor等でreturn awaitやawaitの単純返却がある)return awaitを使っている例が複数)awaitの扱い)return awaitがある箇所)awaitをそのまま返している箇所)上記ファイル群は PR #37 と同じパターン(tryLoadImportMap/importPlugin の実装がほぼ同様、単純に別関数の Promise を await して返している箇所がある)でした。
想定する修正内容(リポジトリ毎に同様)
return awaitになっている単純ラッパーはreturn ...に置換(try/catch 等でスタック取り扱いに差が出る箇所は除外)。return await削除は try/catch によるスタック保持が不要な単純返却箇所のみ行う(PR #37 と同様の安全方針)。安全性と注意点
This pull request was created from Copilot chat.
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.