-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: lazy load yazi.nvim modules by default (#253)
Previously yazi.nvim would load most of its modules up front when required. This is not ideal as typically this delays Neovim's startup time. Although the delay is measured in milliseconds, it might add up if tens of other plugins need to be loaded too. This commit changes the behavior so that yazi.nvim only loads the modules when they are actually needed. The number of loaded modules has changed from 17 to 7, but I did not measure the startup time difference.
- Loading branch information
1 parent
1b44d62
commit f832c3c
Showing
6 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { startNeovimWithYa } from "./using-ya-to-read-events/startNeovimWithYa" | ||
|
||
describe("lazy loading yazi.nvim", () => { | ||
// The idea is that yazi.nvim exposes its public functions when you call | ||
// `require("yazi")`. It should load as little code up front as possible, | ||
// because some users don't use a package manager like lazy.nvim that | ||
// supports lazy loading modules by default. | ||
|
||
it("delays loading of many source code files", () => { | ||
// Not sure what would be a good way to test lazy loading. For now, just | ||
// load the plugin and see how many modules have been loaded. | ||
// | ||
// Maybe in the future, we can have a better way to do this. | ||
cy.visit("http://localhost:5173") | ||
startNeovimWithYa({ | ||
startupScriptModifications: ["report_loaded_yazi_modules.lua"], | ||
}) | ||
|
||
cy.typeIntoTerminal(":=CountYaziModules(){enter}") | ||
|
||
// NOTE: if this number changes in the future, it's ok. This test is just | ||
// to make sure that we don't accidentally load all modules up front due to | ||
// an unrelated change. | ||
cy.contains("Loaded 7 modules") | ||
}) | ||
}) |
This file contains 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
18 changes: 18 additions & 0 deletions
18
integration-tests/test-environment/config-modifications/report_loaded_yazi_modules.lua
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require('yazi') | ||
|
||
-- selene: allow(unused_variable) | ||
function CountYaziModules() | ||
---@type string[] | ||
local yazi_modules = {} | ||
|
||
for k, _ in pairs(package.loaded) do | ||
if k:sub(1, 4) == 'yazi' then | ||
yazi_modules[#yazi_modules + 1] = k | ||
end | ||
end | ||
|
||
return vim.inspect({ | ||
string.format('Loaded %s modules', #yazi_modules), | ||
table.concat(yazi_modules, ','), | ||
}) | ||
end |
This file contains 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