Avoid performing expensive operations (like module loading, event emissions, or resource allocation) until they are actually needed. This pattern significantly improves startup time and runtime performance by reducing unnecessary work.

Key strategies:

Example of lazy require pattern:

-- Instead of eager loading at plugin initialization:
local foo = require("foo")
vim.api.nvim_create_user_command("MyCommand", function()
    foo.do_something()
end, {})

-- Defer the require until command execution:
vim.api.nvim_create_user_command("MyCommand", function()
    local foo = require("foo")  -- Load only when needed
    foo.do_something()
end, {})

This approach ensures that modules and their dependencies are only loaded when the functionality is actually used, rather than eagerly loading everything at startup. The same principle applies to other expensive operations like network calls, file I/O, or complex computations.