Commit 1bec8475 authored by Ben Siraphob's avatar Ben Siraphob
Browse files

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%).
parent 4ed2dff2
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -1121,11 +1121,16 @@ let
    let
      # Add in the default value for this option, if any.
      defs' =
        (optional (opt ? default) {
        if opt ? default then
          [
            {
              file = head opt.declarations;
              value = mkOptionDefault opt.default;
        })
        ++ defs;
            }
          ]
          ++ defs
        else
          defs;

      # Handle properties, check types, and merge everything together.
      res =