From 1bec8475a6d34b8ae60bb1c3ba91a95798c919b1 Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Tue, 14 Apr 2026 09:41:14 -0700 Subject: [PATCH] lib/modules: skip optional + ++ in evalOptionValue when no default Replace `(optional (opt ? default) { ... }) ++ defs` with a direct if/then/else. When the option has no default, this skips both the list allocation and the ++ concat entirely. Most options do have defaults, but even then we avoid the `optional` function call overhead (closure + env allocation). On NixOS minimal eval: -45K function calls (-0.93%), -3.7K list concats (-1.93%). --- lib/modules.nix | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index 9bf1ac9b4d73..2b40202972ba 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1121,11 +1121,16 @@ let let # Add in the default value for this option, if any. defs' = - (optional (opt ? default) { - file = head opt.declarations; - value = mkOptionDefault opt.default; - }) - ++ defs; + if opt ? default then + [ + { + file = head opt.declarations; + value = mkOptionDefault opt.default; + } + ] + ++ defs + else + defs; # Handle properties, check types, and merge everything together. res =