Skip to content

go/internal/gcimporter: too much CPU wasted on copying bytes #46564

Closed
@g7r

Description

@g7r

What version of Go are you using (go version)?

$ go version
go version go1.16.4 linux/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sz/.cache/go-build"
GOENV="/home/sz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/sz/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/sz/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/sz/sdk/go1.16.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/sz/sdk/go1.16.4/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3202951029=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm using go vet to do static checks on my project code. Said io.ReadAll wastes some 30% of time on my codebase. I've managed to reproduce the issue on smaller codebase. The code to reproduce is here: https://gist.githubusercontent.com/g7r/fef9fbf7577bb380de26587c08681b12/raw/1486d5d986f5f3222befca5197cee806632d82d2/repro_test.go. Run go test -bench . -benchtime 10000x -cpuprofile cpu.prof repro_test.go to gather profile.

What did you expect to see?

I expect not to see that large chunk of profile is dedicated to move memory while reading file into byte slice.

What did you see instead?

A lot of memory is being moved during file read. See attached profile screenshot: 2021-06-01-003911_3840x2073_scrot

I suggest we should remove io.ReadAll and use Reader in iImportData.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Performance

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions