From 11ad0c83554954a7f820238cd94d51a124581fc7 Mon Sep 17 00:00:00 2001
From: Rosen Penev <rosenp@gmail.com>
Date: Sat, 7 Jan 2023 00:18:34 -0800
Subject: [PATCH] include: use libdeflate's gzip to decompress

libdeflate decompresses much faster than gzip.

Example:

~/d/openwrt> time gzip -dc dl/cmake-3.25.1.tar.gz > /dev/null

________________________________________________________
Executed in    1.01 secs      fish           external
   usr time  912.61 millis    1.67 millis  910.94 millis
   sys time   32.21 millis    0.25 millis   31.96 millis

~/d/openwrt> time libdeflate-gzip -dc dl/cmake-3.25.1.tar.gz > /dev/null

________________________________________________________
Executed in  523.04 millis    fish           external
   usr time  415.48 millis    1.07 millis  414.41 millis
   sys time  107.74 millis    0.15 millis  107.59 millis

~/d/openwrt> time gzip -dc dl/tessdata-4.1.0.tar.gz > /dev/null

________________________________________________________
Executed in    8.99 secs    fish           external
   usr time    8.90 secs  530.00 micros    8.90 secs
   sys time    0.07 secs   63.00 micros    0.07 secs

~/d/openwrt> time libdeflate-gzip -dc dl/tessdata-4.1.0.tar.gz > /dev/null

________________________________________________________
Executed in    2.74 secs    fish           external
   usr time    2.38 secs  537.00 micros    2.38 secs
   sys time    0.35 secs   66.00 micros    0.35 secs

Place libdeflate into tools-core as it is needed to decompress other
archives.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 include/kernel-defaults.mk | 2 +-
 include/unpack.mk          | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index 127fa8563af..37c11411395 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -21,7 +21,7 @@ Kernel/Patch:=$(Kernel/Patch/Default)
 ifneq (,$(findstring .xz,$(LINUX_SOURCE)))
   LINUX_CAT:=xzcat
 else
-  LINUX_CAT:=gzip -dc
+  LINUX_CAT:=$(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc
 endif
 
 ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
diff --git a/include/unpack.mk b/include/unpack.mk
index ebece699782..5959d55f4b1 100644
--- a/include/unpack.mk
+++ b/include/unpack.mk
@@ -18,7 +18,7 @@ ifeq ($(strip $(UNPACK_CMD)),)
 
     ifeq ($(filter gz tgz,$(EXT)),$(EXT))
       EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
-      DECOMPRESS_CMD:=gzip -dc $(DL_DIR)/$(PKG_SOURCE) |
+      DECOMPRESS_CMD:=$(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc $(DL_DIR)/$(PKG_SOURCE) |
     endif
     ifeq ($(filter bzip2 bz2 bz tbz2 tbz,$(EXT)),$(EXT))
       EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
@@ -56,7 +56,7 @@ ifeq ($(strip $(UNPACK_CMD)),)
     endif
     # replace zcat with $(ZCAT), because some system don't support it properly
     ifeq ($(PKG_CAT),zcat)
-      UNPACK_CMD=gzip -dc $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
+      UNPACK_CMD=$(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
     endif
   endif
 endif
-- 
GitLab