Skip to content

v1.2.0

Compare
Choose a tag to compare
@cshum cshum released this 11 Oct 14:28
· 206 commits to master since this release

Improved Memory Allocation

imagor v1.2.0 improved average memory usage over 30% compare with v1.1.5. This is done by revamping the streaming mechanisms to be more efficient and less memory allocations and copy operations. By doing so imagor introduced 2 reusable Go packages seekstream and fanoutreader that incorporated into imagor.Blob mechanisms:

seekstream

seekstream allows seeking on non-seekable io.ReadCloser source by buffering read data using memory or temp file.

https://pkg.go.dev/github.com/cshum/imagor/seekstream

import  "github.com/cshum/imagor/seekstream"
... 
var source io.ReadCloser // non-seekable
var buffer seekstream.Buffer // memory or temp file buffer
... 
var rs io.ReadSeekCloser = seekstream.New(source, buffer) // seekable

fanoutreader

fanoutreader allows fanout arbitrary number of reader streams concurrently from one data source with known total size, using channel and memory buffer.

https://github.com/cshum/imagor/tree/master/fanoutreader

import  "github.com/cshum/imagor/fanoutreader"
... 
// http source with known size via Content-Length header
resp, _ := http.DefaultClient.Get("https://raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png")
size, _ := strconv.Atoi(resp.Header.Get("Content-Length"))
fanout := fanoutreader.New(resp.Body, size) // create fanout from single reader source

var wg sync.WaitGroup
for i := 0; i < 10; i++ {
	wg.Add(1)
	go func(i int) {
		reader := fanout.NewReader() // spawn new reader
		defer reader.Close()
		file, _ := os.Create(fmt.Sprintf("gopher-%d.png", i))
		defer file.Close()
		_, _ = io.Copy(file, reader) // read concurrently alongside other readers
		wg.Done()
	}(i)
}
wg.Wait()

What's Changed

  • feat(imagor): blob.NewReadSeeker for unknown size or over 100mb by @cshum in #208
  • feat(seekstream): unified seek stream package for memory or temp file buffer by @cshum in #210
  • build(deps): bump github.com/aws/aws-sdk-go from 1.44.106 to 1.44.114 by @dependabot in #207
  • feat(fanout): unified fanout concurrent reader by @cshum in #211
  • feat: seekstream and fanoutreader by @cshum in #212

Full Changelog: v1.1.9...v1.2.0