packages: Rewrite 'transitive-inputs' to be linear and remove duplicates.
authorLudovic Courtès <ludo@gnu.org>
Sat, 11 Jul 2015 21:13:24 +0000 (23:13 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sat, 11 Jul 2015 23:27:00 +0000 (01:27 +0200)
commit161094c8e2b46128544b85dae8e97d4fcb2818c0
tree00f9eb24f608fd5b75ca8298ae6dc781f0a119fa
parent686784d0b958478a0fd8a2fbf69755ceea2d27ec
packages: Rewrite 'transitive-inputs' to be linear and remove duplicates.

There were two issues:

  1. Use of 'delete-duplicates', which is quadratic, was a serious problem for
     closures with lots of propagated inputs, such as that of the 'hydra'
     package (several minutes for 'guix build hydra -n'!).

  2. The 'delete-duplicates' call essentially had no effect since duplicate
     inputs typically had a different label and were thus kept.  For
     instance, (bag-transitive-inputs (package->bag inkscape)) would return
     216 items whereas (delete-duplicates (map cdr THAT)) contains only 67
     items.

     The new implementation returns 67 items in this case.  For 'hydra', we're
     down from 42211 items to 361, and roughly 13s for 'guix build hydra'.

* guix/packages.scm (transitive-inputs): Rewrite as a breadth-first
  traversal.  Remove duplicate propagated inputs.
* tests/packages.scm ("package-transitive-inputs", "package->bag, propagated
  inputs"): Adjust to use simple labels for propagated inputs, without "/".
  ("package-transitive-inputs, no duplicates"): New test.
guix/packages.scm
tests/packages.scm