From 505e74df58ce0f3a524b50fbe26ee17a02aec83d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 26 Aug 2023 14:41:03 -0600 Subject: [PATCH] Revert "Try replacing jpeg library to reduce allocs" This reverts commit d3eb5a99d6338d9049a1886b5e0b86996f5b5dc7. --- .github/workflows/main.yml | 4 --- Dockerfile | 2 +- go.mod | 2 +- go.sum | 6 ++--- jpeg2/jpeg_picker.go | 39 ----------------------------- thumbnailing/i/jpg.go | 3 +-- util/readers/buffer_reads_reader.go | 4 --- 7 files changed, 5 insertions(+), 55 deletions(-) delete mode 100644 jpeg2/jpeg_picker.go diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53551d7c..bd31a394 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,6 @@ jobs: go-version: '1.20' - name: "Install libheif" run: "chmod +x ./.github/workflows/build-libheif.sh && ./.github/workflows/build-libheif.sh" - - name: "Install libjpeg-turbo" - run: "sudo apt-get install libjpeg-turbo-dev" - run: './build.sh' # verify the thing compiles static: name: 'Go Static (1.20)' @@ -25,8 +23,6 @@ jobs: go-version: '1.20' - name: "Install libheif" run: "chmod +x ./.github/workflows/build-libheif.sh && ./.github/workflows/build-libheif.sh" - - name: "Install libjpeg-turbo" - run: "sudo apt-get install libjpeg-turbo-dev" - name: "Prepare: compile assets" run: "GOBIN=$PWD/bin go install -v ./cmd/compile_assets" - name: "Run: compile assets" diff --git a/Dockerfile b/Dockerfile index 497b93b7..bfda3d7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM golang:1.20-alpine AS builder # Install build dependencies -RUN apk add --no-cache git musl-dev dos2unix build-base libde265-dev libheif-dev libjpeg-turbo-dev +RUN apk add --no-cache git musl-dev dos2unix build-base libde265-dev libheif-dev WORKDIR /opt COPY . /opt diff --git a/go.mod b/go.mod index 40dcf398..2a591c3a 100644 --- a/go.mod +++ b/go.mod @@ -58,7 +58,6 @@ require ( github.com/t2bot/go-typed-singleflight v0.0.3 github.com/testcontainers/testcontainers-go v0.23.0 github.com/testcontainers/testcontainers-go/modules/postgres v0.23.0 - github.com/viam-labs/go-libjpeg v0.3.2-0.20230621193101-e6b235025092 golang.org/x/sync v0.3.0 golang.org/x/term v0.11.0 ) @@ -116,6 +115,7 @@ require ( github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect github.com/rs/xid v1.5.0 // indirect + github.com/smartystreets/assertions v1.0.0 // indirect golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/sys v0.11.0 // indirect diff --git a/go.sum b/go.sum index 4b13b0c7..2d6aacba 100644 --- a/go.sum +++ b/go.sum @@ -340,7 +340,8 @@ github.com/sebest/xff v0.0.0-20210106013422-671bd2870b3a/go.mod h1:wozgYq9WEBQBa github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= +github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8= +github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -370,12 +371,9 @@ github.com/testcontainers/testcontainers-go v0.23.0 h1:ERYTSikX01QczBLPZpqsETTBO github.com/testcontainers/testcontainers-go v0.23.0/go.mod h1:3gzuZfb7T9qfcH2pHpV4RLlWrPjeWNQah6XlYQ32c4I= github.com/testcontainers/testcontainers-go/modules/postgres v0.23.0 h1:OEGUC1YTN1RyS4xqsHmlyYkBWm9lMJcswoV4JSHJQOM= github.com/testcontainers/testcontainers-go/modules/postgres v0.23.0/go.mod h1:YnqIhPwhjqVbJBuvSRJS6pa9Cy1PDRJcrM6T63Uw2ms= -github.com/viam-labs/go-libjpeg v0.3.2-0.20230621193101-e6b235025092 h1:DsILjTWWpYH9jl+AsxqkSdbocxkrHxCwCBgHnYTsnfs= -github.com/viam-labs/go-libjpeg v0.3.2-0.20230621193101-e6b235025092/go.mod h1:BCaeb3/txASzLy3XwzuzqFMs+u0cEf+wdiQQL3TxQVo= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.viam.com/test v1.1.0 h1:KXf8crEwt0bHn5iMsjmXg0vPio/yzKGrfd20sWhe/t4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/jpeg2/jpeg_picker.go b/jpeg2/jpeg_picker.go deleted file mode 100644 index b53e5728..00000000 --- a/jpeg2/jpeg_picker.go +++ /dev/null @@ -1,39 +0,0 @@ -package jpeg2 - -import ( - "image" - gojpeg "image/jpeg" - "io" - - "github.com/turt2live/matrix-media-repo/util/readers" - libjpeg "github.com/viam-labs/go-libjpeg/jpeg" -) - -func Decode(r io.Reader) (image.Image, error) { - br := readers.NewBufferReadsReader(r) - c, err := libjpeg.Decode(r, &libjpeg.DecoderOptions{}) - if err != nil { - r = br.GetRewoundReader() - return gojpeg.Decode(r) - } else { - br.Discard() - } - return c, nil -} - -func DecodeConfig(r io.Reader) (image.Config, error) { - br := readers.NewBufferReadsReader(r) - c, err := libjpeg.DecodeConfig(r) - if err != nil { - r = br.GetRewoundReader() - return gojpeg.DecodeConfig(r) - } else { - br.Discard() - } - return c, nil -} - -func init() { - // We get registered "first", overriding which jpeg decoder is used - image.RegisterFormat("jpeg", "\xff\xd8", Decode, DecodeConfig) -} diff --git a/thumbnailing/i/jpg.go b/thumbnailing/i/jpg.go index 7754f678..7cfd73e4 100644 --- a/thumbnailing/i/jpg.go +++ b/thumbnailing/i/jpg.go @@ -3,10 +3,9 @@ package i import ( "errors" "image" + _ "image/jpeg" "io" - _ "github.com/turt2live/matrix-media-repo/jpeg2" - "github.com/disintegration/imaging" "github.com/turt2live/matrix-media-repo/common/rcontext" "github.com/turt2live/matrix-media-repo/thumbnailing/m" diff --git a/util/readers/buffer_reads_reader.go b/util/readers/buffer_reads_reader.go index e1fb2a22..8382029c 100644 --- a/util/readers/buffer_reads_reader.go +++ b/util/readers/buffer_reads_reader.go @@ -44,7 +44,3 @@ func (r *BufferReadsReader) GetRewoundReader() io.Reader { pr, _ := r.MakeRewoundReader() return pr } - -func (r *BufferReadsReader) Discard() { - r.b.Truncate(0) -}