x/tools/gopls: unimported completions do a lot of work #37183
Labels
FrozenDueToAge
gopls
Issues related to the Go language server, gopls.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
I noticed unimported completions were adding 30ms latency to every completion request via
imports.GetAllCandidates
. It seems to be mostly from allocations:filepath.Join
infindPackage
path.Join
incanonicalize
filepath.Rel
incanUse
strconv.Atoi
inImportPathToAssumedName
(perhaps due to error allocation)There is also an
ioutil.ReadDir
call infindPackage
that gets called hundreds of time. It was trying to read non-existent directories in the module cache that do exist for different versions of the module.Maybe the easiest thing is to offer some way to disable unimported package name candidates, leaving unimported package member candidates. That way we wouldn't call
GetAllCandidates
at all most of the time. I know we don't want config option bloat, though.Maybe another option is to have a very coarse cache of the result of imports.GetAllCandidates that gets busted whenever any watched file event comes? It's weird that everything is mostly cached already but we still do some much work every time.
/cc @heschik
The text was updated successfully, but these errors were encountered: