Skip to content

Commit

Permalink
go/types: use internal/lazyregexp for goVersionRx
Browse files Browse the repository at this point in the history
With benchinit, we see a noticeable improvement in init times:

	name     old time/op    new time/op    delta
	GoTypes    83.4µs ± 0%    43.7µs ± 1%  -47.57%  (p=0.029 n=4+4)

	name     old alloc/op   new alloc/op   delta
	GoTypes    26.5kB ± 0%    18.8kB ± 0%  -29.15%  (p=0.029 n=4+4)

	name     old allocs/op  new allocs/op  delta
	GoTypes       238 ± 0%       154 ± 0%  -35.29%  (p=0.029 n=4+4)

Port the same change to cmd/compile/internal/types and types2.

Updates golang#26775.

Change-Id: Ia1f7c4a4ce9a22d66e2aa9c9b9c341036993adca
Reviewed-on: https://go-review.googlesource.com/c/go/+/460544
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
mvdan committed Jan 20, 2023
1 parent 8259ac4 commit c641d48
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types/goversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package types
import (
"fmt"
"internal/goversion"
"internal/lazyregexp"
"log"
"regexp"
"strconv"

"cmd/compile/internal/base"
Expand Down Expand Up @@ -81,4 +81,4 @@ func currentLang() string {

// goVersionRE is a regular expression that matches the valid
// arguments to the -lang flag.
var goVersionRE = regexp.MustCompile(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)
var goVersionRE = lazyregexp.New(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package types2
import (
"cmd/compile/internal/syntax"
"fmt"
"regexp"
"internal/lazyregexp"
"strconv"
"strings"
)
Expand Down Expand Up @@ -78,4 +78,4 @@ func parseGoVersion(s string) (v version, err error) {
}

// goVersionRx matches a Go version string, e.g. "go1.12".
var goVersionRx = regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
var goVersionRx = lazyregexp.New(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
2 changes: 1 addition & 1 deletion src/go/build/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ var depsRules = `
math/big, go/token
< go/constant;
container/heap, go/constant, go/parser, internal/types/errors, regexp
container/heap, go/constant, go/parser, internal/types/errors, internal/lazyregexp
< go/types;
FMT, internal/goexperiment
Expand Down
4 changes: 2 additions & 2 deletions src/go/types/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"go/ast"
"go/token"
"internal/lazyregexp"
. "internal/types/errors"
"regexp"
"strconv"
"strings"
)
Expand Down Expand Up @@ -80,4 +80,4 @@ func parseGoVersion(s string) (v version, err error) {
}

// goVersionRx matches a Go version string, e.g. "go1.12".
var goVersionRx = regexp.MustCompile(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)
var goVersionRx = lazyregexp.New(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)

0 comments on commit c641d48

Please sign in to comment.