What version of Go are you using (go version)?
$ go version
go version go1.17.6 windows/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\a3367\AppData\Local\go-build
set GOENV=C:\Users\a3367\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\a3367\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\a3367\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.6
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\a3367\work\misc\seg\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\a3367\AppData\Local\Temp\go-build4034705114=/tmp/go-build -gno-record-gcc-switches
gdb --version: GNU gdb (GDB) 8.1
What did you do?
Encode a 23500x45500 image.NRGBA image.
This image is around 4GB uncompressed.
What did you expect to see?
I expected the encoding to finish within 5 seconds.
What did you see instead?
It took longer than 20 seconds.
According to pprof, most time is spent on selecting the png filter type.

If the png library allowed us to simply select the ftNone, this would speed up dramatically.
The below pprof shows this by simulating ftNone with no compression.

This file png_encode.zip is the pprof dump showing png.filter taking a lot time.
One side note, even in the case of no compression, much time is still spent on runtime.memmove, any ideas how to eliminate this? Is this related to garbage collection?
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env)?go envOutputWhat did you do?
Encode a 23500x45500
image.NRGBAimage.This image is around 4GB uncompressed.
What did you expect to see?
I expected the encoding to finish within 5 seconds.
What did you see instead?
It took longer than 20 seconds.
According to pprof, most time is spent on selecting the png filter type.
If the png library allowed us to simply select the
ftNone, this would speed up dramatically.The below
pprofshows this by simulatingftNonewith no compression.This file png_encode.zip is the pprof dump showing
png.filtertaking a lot time.One side note, even in the case of no compression, much time is still spent on
runtime.memmove, any ideas how to eliminate this? Is this related to garbage collection?