Repository: go
Issue: cmd/go: get of module already present in proxy can be slow
Labels: NeedsInvestigation,GoCommand

<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version devel go1.18-d34051bf16 Thu Dec 2 07:04:05 2021 +0000 linux/arm64
</pre>

### Does this issue reproduce with the latest release?

Yes

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/myitcv/gostuff/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="devel go1.18-d34051bf16 Thu Dec 2 07:04:05 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.1s97wmUiwJ/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build99146596=/tmp/go-build -gno-record-gcc-switches"
</pre></details>

### What did you do?

```
$ go get -x cuelang.org/go@v0.4.1-beta.4
# get https://proxy.golang.org/cuelang.org/@v/v0.4.1-beta.4.info
go: downloading cuelang.org/go v0.4.1-beta.4
# get https://proxy.golang.org/cuelang.org/go/@v/v0.4.1-beta.4.zip
# get https://proxy.golang.org/cuelang.org/go/@v/v0.4.1-beta.4.zip: 200 OK (0.202s)
# get https://proxy.golang.org/sumdb/sum.golang.org/supported
# get https://proxy.golang.org/sumdb/sum.golang.org/supported: 410 Gone (0.009s)
# get https://sum.golang.org/lookup/cuelang.org/go@v0.4.1-beta.4
# get https://sum.golang.org/lookup/cuelang.org/go@v0.4.1-beta.4: 200 OK (0.073s)
# get https://sum.golang.org/tile/8/0/x032/326
# get https://sum.golang.org/tile/8/2/000.p/127
# get https://sum.golang.org/tile/8/1/127.p/228
# get https://sum.golang.org/tile/8/1/126
# get https://sum.golang.org/tile/8/0/x032/740.p/38
# get https://sum.golang.org/tile/8/2/000.p/127: 200 OK (0.021s)
# get https://sum.golang.org/tile/8/0/x032/326: 200 OK (0.022s)
# get https://sum.golang.org/tile/8/1/126: 200 OK (0.023s)
# get https://sum.golang.org/tile/8/1/127.p/228: 200 OK (0.025s)
# get https://sum.golang.org/tile/8/0/x032/740.p/38: 200 OK (0.029s)
# get https://sum.golang.org/tile/8/0/x032/033
# get https://sum.golang.org/tile/8/0/x032/033: 200 OK (0.039s)
# get https://proxy.golang.org/cuelang.org/@v/v0.4.1-beta.4.info: 410 Gone (2.429s)
# get https://proxy.golang.org/cuelang.org/go/@v/v0.4.1-beta.4.mod
# get https://proxy.golang.org/cuelang.org/go/@v/v0.4.1-beta.4.mod: 200 OK (0.027s)
**********************
# get https://proxy.golang.org/cuelang.org/go/@v/list
# get https://proxy.golang.org/cuelang.org/go/@v/list: 200 OK (0.042s)
go: added cuelang.org/go v0.4.1-beta.4
go: added golang.org/x/exp v0.0.0-20210126221216-84987778548c
go: added golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449
go: added golang.org/x/tools v0.0.0-20200612220849-54c614fe050c
go: added golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
```

The command stalled at the line `**********************` for a good 15-20 secs.


### What did you expect to see?

* No delay; the proxy already knows about this version
* The `-x` logs to indicate where the delay occurred; the 15-20 secs delay I experienced is not accounted for above

### What did you see instead?

As abve.

Noting a subsequent call had output as follows:

```
$ go get -x cuelang.org/go@v0.4.1-beta.4
# get https://proxy.golang.org/cuelang.org/@v/v0.4.1-beta.4.info
# get https://proxy.golang.org/cuelang.org/@v/v0.4.1-beta.4.info: 410 Gone (2.159s)
# get https://proxy.golang.org/cuelang.org/go/@v/list
# get https://proxy.golang.org/cuelang.org/go/@v/list: 200 OK (0.045s)
```

Here the `go get` command ultimately took as long as it did (~2.5 secs) because of the long response time to:

```
# get https://proxy.golang.org/cuelang.org/@v/v0.4.1-beta.4.info: 410 Gone (2.159s)
```

Given `go get` already by this point got a successful response from:

```
# get https://proxy.golang.org/cuelang.org/go/@v/list: 200 OK (0.045s)
```

could `cmd/go` not optimise to simply "drop" the other requests, given the most specific one returned successfully?

cc @bcmills for `cmd/go` and @heschi in case there is any proxy-related issues here