Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Jan 14, 2024
1 parent 9304c39 commit 2f6c1f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 6 additions & 8 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"io"
"math"
"reflect"
"runtime/debug"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -60,7 +59,7 @@ func NewTransformer() *Transformer {
panic(fmt.Sprintf("vips error, code=%v", err))
}

C.vips_concurrency_set(C.int(1))
C.vips_concurrency_set(C.int(0))
C.vips_cache_set_max_files(C.int(0))
C.vips_cache_set_max_mem(C.size_t(0))
C.vips_cache_set_max(C.int(0))
Expand All @@ -81,6 +80,10 @@ func NewTransformer() *Transformer {
}
}

func (t *Transformer) VipsLeakSet() {
C.vips_leak_set(C.TRUE)
}

func (t *Transformer) Shutdown() {
C.vips_shutdown()
}
Expand Down Expand Up @@ -142,11 +145,6 @@ func Manipulate(buf []byte, opts Options) ([]byte, error) {
return nil, fmt.Errorf("%v\nStack:\n%s", s, debug.Stack()) //nolint: goerr113
}

var data []byte
sh := (*reflect.SliceHeader)(unsafe.Pointer(&data))
sh.Data = uintptr(result.buf)
sh.Len = int(result.len)
sh.Cap = int(result.len)

data := unsafe.Slice((*byte)(result.buf), int(result.len))
return data, nil
}
12 changes: 9 additions & 3 deletions image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/nhost/hasura-storage/image"
Expand Down Expand Up @@ -94,21 +95,26 @@ func TestManipulate(t *testing.T) {

func BenchmarkManipulate(b *testing.B) {
transformer := image.NewTransformer()
orig, err := os.Open("testdata/nhost.jpg")
transformer.VipsLeakSet()
defer transformer.Shutdown()

orig, err := os.Open("/Users/dbarroso/Downloads/asd.jpg")
if err != nil {
b.Fatal(err)
}
defer orig.Close()
for i := 0; i < 100; i++ {
for i := 0; i < 1; i++ {
_, _ = orig.Seek(0, 0)

if err := transformer.Run(
orig,
33399,
io.Discard,
image.Options{Width: 300, Height: 100, Blur: 1.5, Format: image.ImageTypeJPEG},
image.Options{Width: 300 + i, Height: 100, Blur: 1.5, Format: image.ImageTypeJPEG},
); err != nil {
b.Fatal(err)
}
}

time.Sleep(1 * time.Second)
}

0 comments on commit 2f6c1f2

Please sign in to comment.