derivations: Use sets for 'derivations-prerequisites'.

This yields a 46% improvement in 'derivation-prerequisites' invocations
on the Emacs derivation.

* guix/derivations.scm (derivation-prerequisites): Add 'input-set'
  variable, and use it in iterations.
This commit is contained in:
Ludovic Courtès 2015-01-11 23:04:07 +01:00
parent d326767e64
commit ed3592a980

@ -31,6 +31,7 @@
#:use-module (guix hash) #:use-module (guix hash)
#:use-module (guix base32) #:use-module (guix base32)
#:use-module (guix records) #:use-module (guix records)
#:use-module (guix sets)
#:export (<derivation> #:export (<derivation>
derivation? derivation?
derivation-outputs derivation-outputs
@ -162,16 +163,18 @@ download with a fixed hash (aka. `fetchurl')."
(define (derivation-prerequisites drv) (define (derivation-prerequisites drv)
"Return the list of derivation-inputs required to build DRV, recursively." "Return the list of derivation-inputs required to build DRV, recursively."
(let loop ((drv drv) (let loop ((drv drv)
(result '())) (result '())
(let ((inputs (remove (cut member <> result) ; XXX: quadratic (input-set (set)))
(let ((inputs (remove (cut set-contains? input-set <>)
(derivation-inputs drv)))) (derivation-inputs drv))))
(fold loop (fold2 loop
(append inputs result) (append inputs result)
(map (lambda (i) (fold set-insert input-set inputs)
(call-with-input-file (derivation-input-path i) (map (lambda (i)
read-derivation)) (call-with-input-file (derivation-input-path i)
inputs))))) read-derivation))
inputs)))))
(define (offloadable-derivation? drv) (define (offloadable-derivation? drv)
"Return true if DRV can be offloaded, false otherwise." "Return true if DRV can be offloaded, false otherwise."