Skip to content

Commit 987de34

Browse files
committed
internal/lsp/completion: don't use Type.String for checking identity
Completion is very performance sensitive, and building a string to check for *testing.F has a significant cost. StructCompletion-8 20.7ms ±14% 16.8ms ± 1% -18.59% (p=0.000 n=10+10) ImportCompletion-8 1.36ms ± 5% 1.05ms ±18% -22.55% (p=0.000 n=9+10) SliceCompletion-8 23.5ms ± 2% 19.3ms ±18% -17.85% (p=0.000 n=7+10) FuncDeepCompletion-8 17.6ms ± 2% 15.5ms ± 2% -11.82% (p=0.000 n=8+8) CompletionFollowingEdit-8 81.2ms ± 8% 74.2ms ± 5% -8.60% (p=0.000 n=9+9) For golang/go#53992 For golang/go#53798 Change-Id: Ia138cbadce142a424caabe8259bda05bcc536055 Reviewed-on: https://go-review.googlesource.com/c/tools/+/422906 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Robert Findley <[email protected]>
1 parent 5a26068 commit 987de34

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/lsp/source/completion/completion.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ func (c *completer) methodsAndFields(typ types.Type, addressable bool, imp *impo
12451245
c.methodSetCache[methodSetKey{typ, addressable}] = mset
12461246
}
12471247

1248-
if typ.String() == "*testing.F" && addressable {
1248+
if isStarTestingDotF(typ) && addressable {
12491249
// is that a sufficient test? (or is more care needed?)
12501250
if c.fuzz(typ, mset, imp, cb, c.snapshot.FileSet()) {
12511251
return
@@ -1272,6 +1272,19 @@ func (c *completer) methodsAndFields(typ types.Type, addressable bool, imp *impo
12721272
})
12731273
}
12741274

1275+
// isStarTestingDotF reports whether typ is *testing.F.
1276+
func isStarTestingDotF(typ types.Type) bool {
1277+
ptr, _ := typ.(*types.Pointer)
1278+
if ptr == nil {
1279+
return false
1280+
}
1281+
named, _ := ptr.Elem().(*types.Named)
1282+
if named == nil {
1283+
return false
1284+
}
1285+
return named.Obj() != nil && named.Obj().Pkg().Path() == "testing" && named.Obj().Name() == "F"
1286+
}
1287+
12751288
// lexical finds completions in the lexical environment.
12761289
func (c *completer) lexical(ctx context.Context) error {
12771290
var (

0 commit comments

Comments
 (0)