modules/performance: add ability to byte-compile plugin lua dependencies

This commit adds byte compiling of plugin lua dependencies
(specifically propagatedBuildInputs). It's enabled by
`performance.byteCompileLua.luaLib` option.
This commit is contained in:
Stanislav Asunkin 2025-05-09 11:48:06 +03:00
parent 404e56066f
commit 2c6182351f
4 changed files with 108 additions and 1 deletions

View file

@ -0,0 +1,28 @@
/*
Byte compiling of lua dependencies of normalized plugin list
Inputs: List of normalized plugins
Outputs: List of normalized plugins with all the propagatedBuildInputs byte-compiled
*/
{ lib, pkgs }:
let
builders = lib.nixvim.builders.withPkgs pkgs;
inherit (import ./utils.nix lib) mapNormalizedPlugins;
# Byte-compile only lua dependencies
byteCompileDeps =
drv:
drv.overrideAttrs (
prev:
lib.optionalAttrs (prev ? propagatedBuildInputs) {
propagatedBuildInputs = map byteCompile prev.propagatedBuildInputs;
}
);
# Byte-compile derivation (but only if it's a lua module) and its dependencies
byteCompile =
drv:
byteCompileDeps (
if pkgs.luaPackages.luaLib.hasLuaModule drv then builders.byteCompileLuaDrv drv else drv
);
in
mapNormalizedPlugins byteCompileDeps

View file

@ -34,6 +34,9 @@ in
shouldCompilePlugins = byteCompileCfg.enable && byteCompileCfg.plugins;
byteCompilePlugins = import ./byte-compile-plugins.nix { inherit lib pkgs; };
shouldCompileLuaLib = byteCompileCfg.enable && byteCompileCfg.luaLib;
byteCompileLuaLib = import ./byte-compile-lua-lib.nix { inherit lib pkgs; };
shouldCombinePlugins = config.performance.combinePlugins.enable;
combinePlugins = import ./combine-plugins.nix {
inherit lib pkgs;
@ -47,6 +50,7 @@ in
lib.pipe config.extraPlugins (
[ normalizePlugins ]
++ lib.optionals shouldCompilePlugins [ byteCompilePlugins ]
++ lib.optionals shouldCompileLuaLib [ byteCompileLuaLib ]
++ lib.optionals shouldCombinePlugins [ combinePlugins ]
);
};

View file

@ -35,4 +35,7 @@ lib.fix (self: {
# Remove dependencies from all plugins in a list
removeDeps = map (p: p // { plugin = removeAttrs p.plugin [ "dependencies" ]; });
# Apply a map function to each 'plugin' attr of the normalized plugin list
mapNormalizedPlugins = f: map (p: p // { plugin = f p.plugin; });
})