hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 3a3badfd1d4b1d4c9863ecaf029512d36136fa0f
parent df021317a964a482cd1cd579de5a12d50faf0d08
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Fri, 26 Oct 2018 13:45:51 +0200

resource: Serialize image processing

Fixes #5220

Diffstat:
Mresource/image.go | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/resource/image.go b/resource/image.go
@@ -212,6 +212,15 @@ func (i *Image) isJPEG() bool {
 	return strings.HasSuffix(name, ".jpg") || strings.HasSuffix(name, ".jpeg")
 }
 
+// Serialize image processing. The imaging library spins up its own set of Go routines,
+// so there is not much to gain from adding more load to the mix. That
+// can even have negative effect in low resource scenarios.
+// Note that this only effects the non-cached scenario. Once the processed
+// image is written to disk, everything is fast, fast fast.
+const imageProcWorkers = 1
+
+var imageProcSem = make(chan bool, imageProcWorkers)
+
 func (i *Image) doWithImageConfig(action, spec string, f func(src image.Image, conf imageConfig) (image.Image, error)) (*Image, error) {
 	conf, err := parseImageConfig(spec)
 	if err != nil {
@@ -237,6 +246,11 @@ func (i *Image) doWithImageConfig(action, spec string, f func(src image.Image, c
 	}
 
 	return i.spec.imageCache.getOrCreate(i, conf, func(resourceCacheFilename string) (*Image, error) {
+		imageProcSem <- true
+		defer func() {
+			<-imageProcSem
+		}()
+
 		ci := i.clone()
 
 		errOp := action