derivations: Micro-optimize 'derivation'.
* guix/derivations.scm (derivation->string): New procedure. (derivation-hash, derivation): Use it. Memoization here yields a 5% improvement on "guix build -e '(@ (gnu packages emacs) emacs)' -n --no-substitutes".
This commit is contained in:
parent
2c6b7c7d55
commit
be4e38fb6f
|
@ -435,6 +435,14 @@ that form."
|
||||||
port)
|
port)
|
||||||
(display ")" port))))
|
(display ")" port))))
|
||||||
|
|
||||||
|
(define derivation->string
|
||||||
|
(memoize
|
||||||
|
(lambda (drv)
|
||||||
|
"Return the external representation of DRV as a string."
|
||||||
|
(with-fluids ((%default-port-encoding "UTF-8"))
|
||||||
|
(call-with-output-string
|
||||||
|
(cut write-derivation drv <>))))))
|
||||||
|
|
||||||
(define* (derivation->output-path drv #:optional (output "out"))
|
(define* (derivation->output-path drv #:optional (output "out"))
|
||||||
"Return the store path of its output OUTPUT."
|
"Return the store path of its output OUTPUT."
|
||||||
(let ((outputs (derivation-outputs drv)))
|
(let ((outputs (derivation-outputs drv)))
|
||||||
|
@ -517,9 +525,7 @@ in SIZE bytes."
|
||||||
;; the SHA256 port's `write' method gets called for every single
|
;; the SHA256 port's `write' method gets called for every single
|
||||||
;; character.
|
;; character.
|
||||||
(sha256
|
(sha256
|
||||||
(with-fluids ((%default-port-encoding "UTF-8"))
|
(string->utf8 (derivation->string drv)))))))))
|
||||||
(string->utf8 (call-with-output-string
|
|
||||||
(cut write-derivation drv <>)))))))))))
|
|
||||||
|
|
||||||
(define (store-path type hash name) ; makeStorePath
|
(define (store-path type hash name) ; makeStorePath
|
||||||
"Return the store path for NAME/HASH/TYPE."
|
"Return the store path for NAME/HASH/TYPE."
|
||||||
|
@ -685,8 +691,7 @@ derivations where the costs of data transfers would outweigh the benefits."
|
||||||
(drv (add-output-paths drv-masked)))
|
(drv (add-output-paths drv-masked)))
|
||||||
|
|
||||||
(let ((file (add-text-to-store store (string-append name ".drv")
|
(let ((file (add-text-to-store store (string-append name ".drv")
|
||||||
(call-with-output-string
|
(derivation->string drv)
|
||||||
(cut write-derivation drv <>))
|
|
||||||
(map derivation-input-path
|
(map derivation-input-path
|
||||||
inputs))))
|
inputs))))
|
||||||
(set-file-name drv file))))
|
(set-file-name drv file))))
|
||||||
|
|
Loading…
Reference in New Issue