Skip to content

Commit 6f45eeb

Browse files
committed
use go/parser.SkipObjectResolution
We don't use go/ast.Objects, as we use go/types instead. Avoiding this work saves a bit of CPU and memory allocs. name old time/op new time/op delta Build-16 10.2s ± 1% 10.2s ± 1% ~ (p=0.937 n=6+6) name old bin-B new bin-B delta Build-16 5.47M ± 0% 5.47M ± 0% ~ (all equal) name old cached-time/op new cached-time/op delta Build-16 328ms ±14% 321ms ± 6% ~ (p=0.589 n=6+6) name old mallocs/op new mallocs/op delta Build-16 34.8M ± 0% 34.0M ± 0% -2.26% (p=0.010 n=6+4) name old sys-time/op new sys-time/op delta Build-16 5.89s ± 3% 5.89s ± 3% ~ (p=0.937 n=6+6) See golang/go#52463.
1 parent bb3f246 commit 6f45eeb

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ func transformCompile(args []string) ([]string, error) {
726726

727727
var files []*ast.File
728728
for _, path := range paths {
729-
file, err := parser.ParseFile(fset, path, nil, parser.ParseComments)
729+
file, err := parser.ParseFile(fset, path, nil, parser.SkipObjectResolution|parser.ParseComments)
730730
if err != nil {
731731
return nil, err
732732
}

position.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func printFile(file1 *ast.File) ([]byte, error) {
5959
// Syntax errors should be rare, and when they do happen,
6060
// we don't want to point to the original source file on disk.
6161
// That would be confusing, as we've changed the source in memory.
62-
file2, err := parser.ParseFile(fset, "", src, parser.ParseComments)
62+
file2, err := parser.ParseFile(fset, "", src, parser.SkipObjectResolution|parser.ParseComments)
6363
if err != nil {
6464
return nil, fmt.Errorf("re-parse error: %w", err)
6565
}

reverse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ One can reverse a captured panic stack trace as follows:
8080
var files []*ast.File
8181
for _, goFile := range lpkg.GoFiles {
8282
fullGoFile := filepath.Join(lpkg.Dir, goFile)
83-
file, err := parser.ParseFile(fset, fullGoFile, nil, 0)
83+
file, err := parser.ParseFile(fset, fullGoFile, nil, parser.SkipObjectResolution)
8484
if err != nil {
8585
return err
8686
}

0 commit comments

Comments
 (0)