Repository: go
Issue: x/tools/gopls: buildssa analyzer is slow on github.com/aws/aws-sdk-go-v2/service/ec2
Labels: gopls,Tools,gopls/performance

This session involves a gopls that has been modified to enable nilness.Analyzer, which itself has been modified to declare a dummy Fact that it doesn't import or export, so as to cause nilness (and thus buildssa) to be run on all dependencies. The gopls analysis driver has also been instrumented to display the wall time of each buildssa unit. Observe how expensive SSA construction is for the [ec2 package](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/ec2), which has an extraordinary number of methods.

(This is a minimization of a performance problem reported by a user running staticcheck (whose buildir is almost identical to buildssa) on github.com/hashiform/terraform-provider-aws/internal/provider.) See #61178.


```
w$ git clone https://github.com/aws/aws-sdk-go-v2
w$ cd service/ec2
ec2$ (cd ~/w/xtools && go build -o x ./gopls ) && time ~/w/xtools/x --profile.cpu=prof check ./internal/customizations/unit_test.go
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/internal/timeconv 383.709µs
2023/07/21 11:18:39 exec buildssa@net/http/internal/testcert 285.916µs
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/internal/strings 291.541µs
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/internal/sdk 1.026167ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/protocol/ec2query 527.208µs
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/ratelimit 1.357458ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/internal/sync/singleflight 1.268208ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/internal/rand 360.208µs
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/protocol/query 10.287959ms
2023/07/21 11:18:39 exec buildssa@net/http/httptest 14.392416ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws 16.287958ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/defaults 2.928167ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/internal/configsources 4.141917ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 3.565167ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/signer/internal/v4 6.881791ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/middleware 7.872875ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/service/ec2/internal/endpoints 3.785583ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/retry 5.897459ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/transport/http 8.835125ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/aws/signer/v4 8.82425ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/service/ec2/types 25.772458ms
2023/07/21 11:18:39 exec buildssa@github.com/aws/aws-sdk-go-v2/service/internal/presigned-url 8.336917ms
2023/07/21 11:18:41 exec buildssa@github.com/aws/aws-sdk-go-v2/service/ec2 1.056296292s  <--- note
2023/07/21 11:18:41 exec buildssa@github.com/aws/aws-sdk-go-v2/service/ec2/internal/customizations_test [github.com/aws/aws-sdk-go-v2/service/ec2/internal/customizations.test] 25.270583ms

real	0m3.619s
user	0m10.746s
sys	0m1.532s
```


The task of this issue is to bring down the cost of buildssa so that it is proportional to the size of the package and the exportdata and factdata sizes of its direct imports, not to its transitive size. go/ssa eagerly constructs methods for every type reachable via reflection, which seems quite unnecessary.

@findleyr