golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.27k stars 17.47k forks source link

x/crypto/chacha20poly1305: 15% performance regression on certain cpus #67240

Open rfjakob opened 3 months ago

rfjakob commented 3 months ago

Go version

go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/jakob/.cache/go-build'
GOENV='/home/jakob/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/jakob/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/jakob/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/jakob/go/src/github.com/rfjakob/gocryptfs/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2175247311=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Hi, I have a user reporting a 15% performance regression in gocryptfs ( https://github.com/rfjakob/gocryptfs/issues/828 ) due to change https://github.com/golang/go/issues/63871 .

The CPU is Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz so I guess too old for AVX but it does have PSHUFB.

Can PSHUFB be detected at runtime instead?

Reproducer is the built-in gocryptfs speed test:

./gocryptfs -speed

What did you see happen?

With go 1.22: Slow XChaCha20-Poly1305

gocryptfs v2.4.0-15-g9958b63; go-fuse [vendored]; 2024-03-03 go1.22.0 linux/amd64
cpu: Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz; no AES acceleration
[...]
XChaCha20-Poly1305-Go            616.01 MB/s    (selected in auto mode)

What did you expect to see?

With go 1.21: Fast XChaCha20-Poly1305

gocryptfs v2.4.0; go-fuse [vendored]; 2023-10-12 go1.21.3 linux/amd64
cpu: Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz; no AES acceleration
[...]
XChaCha20-Poly1305-Go            728.97 MB/s    (selected in auto mode)
randall77 commented 3 months ago

That processor is 13 years old now. We could make the check dynamic if not building with GOAMD64=v2 or better. The challenge is how do we test that code? I suspect we don't have any processors without PSHUFB support in our trybot fleet. GODEBUG=cpu.X=off for the right value of X might be enough, not sure.

mauri870 commented 3 months ago

There is more discussion going on at https://github.com/golang/go/issues/63872 to discuss how to test GOAMD64=v1 features in the builder fleet.

rfjakob commented 3 months ago

I suspect we don't have any processors without PSHUFB support in our trybot fleet.

The CPU in question does have PSHUFB. Looking at https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels, this makes it a x86-64-v2 CPU.

So the question is more about testing on x86-64-v2. I guess the trybot fleet is x86-64-v3 and later.