golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.28k stars 610 forks source link

Improve performance of reflect mode #214

Closed kishaningithub closed 5 years ago

kishaningithub commented 5 years ago

Mock generation via reflect mode always takes more that 1 second on my mac

$ \time -p mockgen github.com/aws/aws-sdk-go/service/kms/kmsiface KMSAPI > /dev/null
real         1.27
user         0.94
sys          0.33

$ \time -p mockgen github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface DynamoDBAPI > /dev/null
real         1.42
user         0.98
sys          0.34

$ \time -p mockgen github.com/newrelic/go-agent Application > /dev/null
real         1.40
user         0.94
sys          0.34

$ \time -p mockgen github.com/go-redis/redis Cmdable > /dev/null
real         1.03
user         0.64
sys          0.28

Go Environment

$ go version && go env
go version go1.11.1 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kishanb/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/kishanb/Programming/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/57/d256bszn1pd1s2v2xyv94xxc0000gn/T/go-build821184220=/tmp/go-build -gno-record-gcc-switches -fno-common
poy commented 5 years ago

@kishaningithub While this is interesting, I'm inclined to close it for now. I don't know if this induces much/any pain in the normal use case.

However, if I'm misunderstanding why this is causing pain, please feel free to reopen the issue.

kishaningithub commented 5 years ago

@poy Its not causing pain as it gets the job done. Just that it would be nice if it can do things faster. I would like to contribute to this as well if you could point me towards the portions of code responsible for this as i am pretty much new to the code base.

poy commented 5 years ago

Sounds great! I would start with https://github.com/golang/mock/blob/master/mockgen/reflect.go It seems the most relevant for what you are referring to.