fix: defer heavy module loading for faster startup (#272)#275
Merged
esmuellert merged 2 commits intomainfrom Feb 24, 2026
Merged
fix: defer heavy module loading for faster startup (#272)#275esmuellert merged 2 commits intomainfrom
esmuellert merged 2 commits intomainfrom
Conversation
Reduce startup impact from ~15ms to ~0.6ms by deferring heavy requires (UI, diff engine, explorer, history, lifecycle) until first :CodeDiff invocation. Only highlights and virtual_file scheme load at startup. - plugin/codediff.lua: replace 4 eager requires with 2 lightweight ones; wrap command handler to lazy-load codediff.commands - plugin/vscode-diff.lua: lazy-wrap command handler - lua/codediff/ui/init.lua: remove eager lifecycle.setup() call - lua/codediff/ui/view/init.lua: add once-guard to call lifecycle.setup() on first view.create() Closes #272 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Reduces codediff.nvim's startup impact from ~15ms to ~0.6ms (96% reduction) by deferring heavy module loading until the user first invokes
:CodeDiff.Closes #272
Problem
plugin/codediff.luaeagerly loaded 42 Lua modules + a C library via FFI at startup, even when the user never used any diff functionality. This consumed ~15ms on cold start and ~8ms on warm start.Before (startup profiling)
After
Changes
plugin/codediff.lua: Replace 4 eager top-levelrequire()calls with 2 lightweight ones (codediff.ui.highlights+codediff.core.virtual_file). Wrap the:CodeDiffcommand handler to lazy-loadcodediff.commandson first invocation.plugin/vscode-diff.lua: Lazy-wrap the:VscodeDiffcommand handler.lua/codediff/ui/init.lua: Remove eagerlifecycle.setup()call (was registering global autocmds at startup).lua/codediff/ui/view/init.lua: Add once-guard to calllifecycle.setup()on firstview.create(), so cleanup autocmds are only registered when actually needed.What loads at startup (~0.6ms)
codediff.ui.highlights— highlight group definitionscodediff.core.virtual_file—codediff://URL scheme registrationWhat's deferred to first
:CodeDiffinvocationffi.load())WinClosed/TabClosed/BufEnter)Testing
:CodeDiff file,:VscodeDiff, lifecycle cleanup, multi-tab all work