From 6aec4d564c96b4a26497a1a4c613e2791f958062 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Tue, 20 Sep 2022 17:22:12 -0700 Subject: [PATCH] archive: remove pgzip, use gzip from go std lib (MR 25) This replaces the parallel gzip with the boring gzip from Go's standard lib. The main motivations for doing this are: 1) Reduce runtime memory requirements 2) shed some external dependencies There's obviously a trade-off with compression speed/time (as seen below), but I feel like it's a worthwhile trade-off. Note that there's likely very little impact to boot performance wrt extracting these archives, the compression levels are similar. Measured on a Shift 6mq, which is a very fast phone... ** compress/gzip: User time (seconds): 1.81 System time (seconds): 0.38 Percent of CPU this job got: 104% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.09 Maximum resident set size (kbytes): 62024 -rw-r--r-- 1 clayton clayton 6.1M Sep 20 17:20 initramfs -rw-r--r-- 1 clayton clayton 2.5M Sep 20 17:20 initramfs-extra ** pgzip: User time (seconds): 1.19 System time (seconds): 0.48 Percent of CPU this job got: 159% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.05 Maximum resident set size (kbytes): 109952 -rw-r--r-- 1 clayton clayton 6.8M Sep 20 17:20 initramfs -rw-r--r-- 1 clayton clayton 2.8M Sep 20 17:20 initramfs-extra inspired by: https://gitlab.com/postmarketOS/pmaports/-/issues/1704 --- go.mod | 2 -- go.sum | 5 ----- internal/archive/archive.go | 8 ++------ 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 419c7eb..c90300f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,5 @@ go 1.16 require ( github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e - github.com/klauspost/compress v1.13.3 // indirect - github.com/klauspost/pgzip v1.2.5 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c ) diff --git a/go.sum b/go.sum index 010466a..521fae3 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,4 @@ github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e h1:hHg27A0RSSp2Om9lubZpiMgVbvn39bsUmW9U5h0twqc= github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/klauspost/compress v1.13.3 h1:BtAvtV1+h0YwSVwWoYXMREPpYu9VzTJ9QDI1TEg/iQQ= -github.com/klauspost/compress v1.13.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= -github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE= -github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/internal/archive/archive.go b/internal/archive/archive.go index b2a21fc..6839593 100644 --- a/internal/archive/archive.go +++ b/internal/archive/archive.go @@ -5,7 +5,7 @@ package archive import ( "bytes" - "compress/flate" + "compress/gzip" "fmt" "io" "log" @@ -17,7 +17,6 @@ import ( "syscall" "github.com/cavaliercoder/go-cpio" - "github.com/klauspost/pgzip" "gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist" "gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil" ) @@ -222,10 +221,7 @@ func (archive *Archive) writeCompressed(path string, mode os.FileMode) error { return err } - gz, err := pgzip.NewWriterLevel(fd, flate.BestSpeed) - if err != nil { - return err - } + gz := gzip.NewWriter(fd) if _, err = io.Copy(gz, archive.buf); err != nil { return err