Limit spawned goroutines to GOMAXPROCS(0).

This change sets the number of spawned goroutines to the GOMAXPROCS
value set by the user.

Using more goroutines than available execution threads is slightly
detrimental to performance (~0.5%), and prevents users of the library
from controlling the number of spawned goroutines.
This commit is contained in:
Charlie Vieth 2015-03-15 17:59:38 -04:00
parent d8255b0421
commit 076a9ce3b9

View File

@ -97,7 +97,7 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
} }
taps, kernel := interp.kernel() taps, kernel := interp.kernel()
cpus := runtime.NumCPU() cpus := runtime.GOMAXPROCS(0)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
// Generic access to image.Image is slow in tight loops. // Generic access to image.Image is slow in tight loops.
@ -283,7 +283,7 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
func resizeNearest(width, height uint, scaleX, scaleY float64, img image.Image, interp InterpolationFunction) image.Image { func resizeNearest(width, height uint, scaleX, scaleY float64, img image.Image, interp InterpolationFunction) image.Image {
taps, _ := interp.kernel() taps, _ := interp.kernel()
cpus := runtime.NumCPU() cpus := runtime.GOMAXPROCS(0)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
switch input := img.(type) { switch input := img.(type) {