x/tools/imports: pathological behaviour when package result is in same module #32726
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Per discussion with @heschik on Slack.
On a machine with a large amount of code in
$GOPATH/pkg/mod
, the following script will roughly show the slow performance. I think this is representative of the general case; other specific examples which are harder to reproduce exactly, exhibit even worse behaviour but are, I think, the same class of problem.On my machine (~5GB of code in the module cache), I see the following:
What did you expect to see?
goimports
taking next to no time at all, because there is a "match" within the current module.I think
imports
needs prioritise its search according to module distance from the main module, falling back to the module cache as a last resort.Furthermore, I don't think the query against the module cache should be kicked off until modules reachable from the main module (including standard library of course) have been evaluated. Reason being, with a large amount of code in the module cache, the processing and IO cost can be huge.
What did you see instead?
goimports
taking a long time, ~10 seconds for some particularly bad cases. Ingopls
, if you are invokingimports
via "format-on-save", which is a blocking operation, this is particularly painful.cc for FYI @stamblerre @ianthehat
The text was updated successfully, but these errors were encountered: