Subject: [bug#43516] [PATCH core-updates] packages: Enable multi-threaded xz compression when repacking source.

From: Maxim Cournoyer <[email-masked]>
Date: Sat, 19 Sep 2020 13:03:57 -0400

The xz compression is slow; using multiple threads/cores yields a linear
performance improvement.

* guix/packages.scm (patch-and-repack): Ensure xz is invoked with --threads=N
by setting the XZ_DEFAULTS environment variable.
---
 guix/packages.scm | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/guix/packages.scm b/guix/packages.scm
index 6598bd3149..678007a807 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2016 Alex Kost <[email-masked]>
 ;;; Copyright © 2017, 2019, 2020 Efraim Flashner <[email-masked]>
 ;;; Copyright © 2019 Marius Bakke <[email-masked]>
+;;; Copyright © 2020 Maxim Cournoyer <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -693,6 +694,11 @@ specifies modules in scope when evaluating SNIPPET."
             (setenv "PATH" (string-append #+xz "/bin" ":"
                                           #+decomp "/bin"))
 
+            ;; Enable multi-threaded compression for xz.
+            (setenv "XZ_DEFAULTS" (string-append "--threads="
+                                                 (number->string
+                                                  (parallel-job-count))))
+
             ;; SOURCE may be either a directory or a tarball.
             (if (file-is-directory? #+source)
                 (let* ((store     (%store-directory))
-- 
2.28.0