derivations: Avoid string-to-bytevector conversions.

On Guile 2.2.1, this yields a 5% speedup on:

  guix build libreoffice xmonad certbot -n --no-substitutes --no-build-hook

* guix/derivations.scm (derivation->string): Rename to...
(derivation->bytevector): ... this.  Use 'open-bytevector-output-port'
instead of 'call-with-output-string'.
(derivation-hash): Remove string-to-bytevector conversion before
'sha256' call.
(build-expression->derivation): Use 'add-data-to-store' and an
bytevector port instead of a string port for the expression.
This commit is contained in:
Ludovic Courtès 2017-04-20 18:46:38 +02:00
parent 358b10b22b
commit 2dce88d5bb
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 22 additions and 19 deletions

View File

@ -566,12 +566,14 @@ that form."
(write-list env-vars write-env-var port)
(display ")" port))))
(define derivation->string
(define derivation->bytevector
(mlambda (drv)
"Return the external representation of DRV as a string."
"Return the external representation of DRV as a UTF-8-encoded string."
(with-fluids ((%default-port-encoding "UTF-8"))
(call-with-output-string
(cut write-derivation drv <>)))))
(call-with-values open-bytevector-output-port
(lambda (port get-bytevector)
(write-derivation drv port)
(get-bytevector))))))
(define* (derivation->output-path drv #:optional (output "out"))
"Return the store path of its output OUTPUT. Raise a
@ -670,8 +672,7 @@ derivation at FILE."
;; XXX: At this point this remains faster than `port-sha256', because
;; the SHA256 port's `write' method gets called for every single
;; character.
(sha256
(string->utf8 (derivation->string drv))))))))
(sha256 (derivation->bytevector drv)))))))
(define (store-path type hash name) ; makeStorePath
"Return the store path for NAME/HASH/TYPE."
@ -872,8 +873,8 @@ output should not be used."
system builder args env-vars #f))
(drv (add-output-paths drv-masked)))
(let* ((file (add-text-to-store store (string-append name ".drv")
(derivation->string drv)
(let* ((file (add-data-to-store store (string-append name ".drv")
(derivation->bytevector drv)
(map derivation-input-path inputs)))
(drv* (set-field drv (derivation-file-name) file)))
(hash-set! %derivation-cache file drv*)
@ -1237,23 +1238,25 @@ ALLOWED-REFERENCES, DISALLOWED-REFERENCES, LOCAL-BUILD?, and SUBSTITUTABLE?."
;; Guile sets it, but remove it to avoid conflicts when
;; building Guile-using packages.
(unsetenv "LD_LIBRARY_PATH")))
(builder (add-text-to-store store
(builder (add-data-to-store store
(string-append name "-guile-builder")
;; Explicitly use UTF-8 for determinism,
;; and also because UTF-8 output is faster.
(with-fluids ((%default-port-encoding
"UTF-8"))
(call-with-output-string
(lambda (port)
(write prologue port)
(write
`(exit
,(match exp
((_ ...)
(remove module-form? exp))
(_ `(,exp))))
port))))
(call-with-values
open-bytevector-output-port
(lambda (port get-bv)
(write prologue port)
(write
`(exit
,(match exp
((_ ...)
(remove module-form? exp))
(_ `(,exp))))
port)
(get-bv))))
;; The references don't really matter
;; since the builder is always used in