on iko/ghcjs-patch-master help sign in
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

commit3856d2d24dca0ecc71fcfc314253a2a2d07a3c4f authorTeo Camarasu <635786+TeofilC@users.noreply.github.com> dateMon 28 Jun 2021, 05:46 (5 years ago) parente72866f
2 files changed+6−12
builder/shell-for.nix+5−4 lib/default.nix+1−8
builder/shell-for.nix+5−4
@@ -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+1−8
@@ -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;