Skip to content

Commit

Permalink
perf(back): #1101 faster init
Browse files Browse the repository at this point in the history
- Stop checking if path exists as it was collected a few
milliseconds ago
- Only declare some trivial variables once
  • Loading branch information
dsalaza4 committed Jun 22, 2023
1 parent 78993b5 commit 80aafe7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/evaluator/modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,19 @@
};
configAsJson = toFileJson "config.json" config.config;
outputs = let
# Trivial
makesDirsNoRoot = lib.remove "/" config.extendingMakesDirs;
makesDirsToReplace = makesDirsNoRoot ++ ["/main.nix"];
emptyList = builtins.map (_: "") makesDirsToReplace;

# Load an attr set distributed across many files and directories
attrs = let
pathInConfig = dir:
builtins.any
(makesDir: lib.hasInfix makesDir dir)
config.extendingMakesDirs;
pathExists = dir: builtins.pathExists (projectSrc + dir);
attrName = dir: let
makesDirsNoRoot = lib.remove "/" config.extendingMakesDirs;
from = makesDirsNoRoot ++ ["/main.nix"];
to = builtins.genList (_: "") ((builtins.length makesDirsNoRoot) + 1);
replaced = builtins.replaceStrings from to dir;
replaced = builtins.replaceStrings makesDirsToReplace emptyList dir;
in
if replaced != ""
then replaced
Expand All @@ -117,7 +118,7 @@
(
dir:
attrsOptional
(pathInConfig dir && pathExists dir)
(pathInConfig dir)
{"${attrName dir}" = import (projectSrc + dir) args;}
)
(fromJson attrPaths).attrs
Expand Down

0 comments on commit 80aafe7

Please sign in to comment.