Skip to content

Commit 3856d2d

Browse files
authored
Improve shellFor selectComponents performance (#1146)
* factor out isSelectedComponent * Optimise `flatLibDepends` We no longer force the `outPath` attribute to avoid instantiating the derivation, which is expensive
1 parent e72866f commit 3856d2d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

builder/shell-for.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,20 @@ let
5555
(builtins.map (x: lib.nameValuePair (x.name) x)
5656
(haskellLib.flatLibDepends {depends = directlySelectedComponents;}));
5757

58+
isSelectedComponent =
59+
comp: selectedComponentsBitmap."${((haskellLib.dependToLib comp).name or null)}" or false;
5860
selectedComponentsBitmap =
5961
lib.mapAttrs
60-
(_: x: (builtins.any
61-
(dep: selectedComponentsBitmap."${(haskellLib.dependToLib dep).name}") x.config.depends))
62+
(_: x: (builtins.any isSelectedComponent x.config.depends))
6263
transitiveDependenciesComponents
6364
// builtins.listToAttrs (map (x: lib.nameValuePair x.name true) directlySelectedComponents); # base case
6465

6566
selectedComponents =
66-
lib.filter (x: selectedComponentsBitmap."${x.name}") (lib.attrValues transitiveDependenciesComponents);
67+
lib.filter isSelectedComponent (lib.attrValues transitiveDependenciesComponents);
6768

6869
# Given a list of `depends`, removes those which are selected components
6970
removeSelectedInputs =
70-
lib.filter (input: !(selectedComponentsBitmap."${((haskellLib.dependToLib input).name or null)}" or false));
71+
lib.filter (input: !(isSelectedComponent input));
7172

7273
# The configs of all the selected components
7374
selectedConfigs = map (c: c.config) selectedComponents

lib/default.nix

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,7 @@ in {
132132
## flatLibDepends :: Component -> [Package]
133133
flatLibDepends = component:
134134
let
135-
# this is a minor improvement over the "cannot coerce set to string"
136-
# error. It will now say:
137-
#
138-
# > The option `packages.Win32.package.identifier.name' is used but not defined.
139-
#
140-
# which indicates that the package.Win32 is missing and not defined.
141-
getKey = x: if x ? "outPath" then "${x}" else (throw x.identifier.name);
142-
makePairs = map (p: rec { key=getKey val; val=(p.components.library or p); });
135+
makePairs = map (p: rec { key=val.name; val=(p.components.library or p); });
143136
closure = builtins.genericClosure {
144137
startSet = makePairs component.depends;
145138
operator = {val,...}: makePairs val.config.depends;

0 commit comments

Comments
 (0)