derivations: Memoize `read-derivation'.

* guix/derivations.scm (read-derivation): Rename to...
  (%read-derivation): ... this.
  (read-derivation): New procedure.
  This reduces the execution of "guix-build gdb" from 2.5s to 1.7s.
master
Ludovic Courtès 2013-01-30 18:56:20 +01:00
parent fce2394e7d
commit d0840e4a23
1 changed files with 16 additions and 3 deletions

View File

@ -155,9 +155,8 @@ DRV and not already available in STORE, recursively."
inputs)
(map derivation-input-sub-derivations inputs))))))
(define (read-derivation drv-port)
"Read the derivation from DRV-PORT and return the corresponding
<derivation> object."
(define (%read-derivation drv-port)
;; Actually read derivation from DRV-PORT.
(define comma (string->symbol ","))
@ -222,6 +221,20 @@ DRV and not already available in STORE, recursively."
(loop (read drv-port)
(cons (ununquote exp) result))))))
(define read-derivation
(let ((cache (make-weak-value-hash-table 200)))
(lambda (drv-port)
"Read the derivation from DRV-PORT and return the corresponding
<derivation> object."
;; Memoize that operation because `%read-derivation' is quite expensive,
;; and because the same argument is read more than 15 times on average
;; during something like (package-derivation s gdb).
(let ((file (and=> (port-filename drv-port) basename)))
(or (and file (hash-ref cache file))
(let ((drv (%read-derivation drv-port)))
(hash-set! cache file drv)
drv))))))
(define (write-derivation drv port)
"Write the ATerm-like serialization of DRV to PORT. See Section 2.4 of
Eelco Dolstra's PhD dissertation for an overview of a previous version of