mirror of
https://github.com/golang/go
synced 2024-11-23 07:20:06 -07:00
cmd/compile: disable typPtr caching in the backend
The only new Types that the backend introduces are pointers to Types generated by the frontend. Usually, when we generate a *T, we cache the resulting Type in T, to avoid recreating it later. However, that caching is not concurrency safe. Rather than add mutexes, this CL disables that caching before starting the backend. The backend generates few enough new *Ts that the performance impact of this is small, particularly if we pre-create some commonly used *Ts. Updates #15756 name old alloc/op new alloc/op delta Template 40.3MB ± 0% 40.4MB ± 0% +0.18% (p=0.001 n=10+10) Unicode 29.8MB ± 0% 29.8MB ± 0% +0.11% (p=0.043 n=10+9) GoTypes 114MB ± 0% 115MB ± 0% +0.33% (p=0.000 n=9+10) SSA 855MB ± 0% 859MB ± 0% +0.40% (p=0.000 n=10+10) Flate 25.7MB ± 0% 25.8MB ± 0% +0.35% (p=0.000 n=10+10) GoParser 31.9MB ± 0% 32.1MB ± 0% +0.58% (p=0.000 n=10+10) Reflect 79.6MB ± 0% 79.9MB ± 0% +0.31% (p=0.000 n=10+10) Tar 26.9MB ± 0% 26.9MB ± 0% +0.21% (p=0.000 n=10+10) XML 42.5MB ± 0% 42.7MB ± 0% +0.52% (p=0.000 n=10+9) name old allocs/op new allocs/op delta Template 394k ± 1% 393k ± 0% ~ (p=0.529 n=10+10) Unicode 319k ± 1% 319k ± 0% ~ (p=0.720 n=10+9) GoTypes 1.15M ± 0% 1.15M ± 0% +0.14% (p=0.035 n=10+10) SSA 7.53M ± 0% 7.56M ± 0% +0.45% (p=0.000 n=9+10) Flate 238k ± 0% 238k ± 1% ~ (p=0.579 n=10+10) GoParser 318k ± 1% 320k ± 1% +0.64% (p=0.001 n=10+10) Reflect 1.00M ± 0% 1.00M ± 0% ~ (p=0.393 n=10+10) Tar 254k ± 0% 254k ± 1% ~ (p=0.075 n=10+10) XML 395k ± 0% 397k ± 0% +0.44% (p=0.001 n=10+9) Change-Id: I6c031ed4f39108f26969c5712b73aa2fc08cd10a Reviewed-on: https://go-review.googlesource.com/38417 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
2730c17a86
commit
f9fb4579e1
@ -46,6 +46,21 @@ func initssaconfig() {
|
||||
Float64Ptr: typPtr(Types[TFLOAT64]),
|
||||
BytePtrPtr: typPtr(typPtr(Types[TUINT8])),
|
||||
}
|
||||
// Generate a few pointer types that are uncommon in the frontend but common in the backend.
|
||||
// Caching is disabled in the backend, so generating these here avoids allocations.
|
||||
_ = typPtr(Types[TINTER]) // *interface{}
|
||||
_ = typPtr(typPtr(Types[TSTRING])) // **string
|
||||
_ = typPtr(typPtr(idealstring)) // **string
|
||||
_ = typPtr(typSlice(Types[TINTER])) // *[]interface{}
|
||||
_ = typPtr(typPtr(bytetype)) // **byte
|
||||
_ = typPtr(typSlice(bytetype)) // *[]byte
|
||||
_ = typPtr(typSlice(Types[TSTRING])) // *[]string
|
||||
_ = typPtr(typSlice(idealstring)) // *[]string
|
||||
_ = typPtr(typPtr(typPtr(Types[TUINT8]))) // ***uint8
|
||||
_ = typPtr(Types[TINT16]) // *int16
|
||||
_ = typPtr(Types[TINT64]) // *int64
|
||||
_ = typPtr(errortype) // *error
|
||||
typPtrCacheEnabled = false
|
||||
ssaConfig = ssa.NewConfig(thearch.LinkArch.Name, types, Ctxt, Debug['N'] == 0)
|
||||
if thearch.LinkArch.Name == "386" {
|
||||
ssaConfig.Set387(thearch.Use387)
|
||||
|
@ -487,6 +487,11 @@ func typMap(k, v *Type) *Type {
|
||||
return t
|
||||
}
|
||||
|
||||
// typPtrCacheEnabled controls whether *T Types are cached in T.
|
||||
// Caching is disabled just before starting the backend.
|
||||
// This allows the backend to run concurrently.
|
||||
var typPtrCacheEnabled = true
|
||||
|
||||
// typPtr returns the pointer type pointing to t.
|
||||
func typPtr(elem *Type) *Type {
|
||||
if elem == nil {
|
||||
@ -501,14 +506,16 @@ func typPtr(elem *Type) *Type {
|
||||
}
|
||||
|
||||
if Tptr == 0 {
|
||||
Fatalf("typPtr: Tptr not intialized")
|
||||
Fatalf("typPtr: Tptr not initialized")
|
||||
}
|
||||
|
||||
t := typ(Tptr)
|
||||
t.Extra = PtrType{Elem: elem}
|
||||
t.Width = int64(Widthptr)
|
||||
t.Align = uint8(Widthptr)
|
||||
elem.ptrTo = t
|
||||
if typPtrCacheEnabled {
|
||||
elem.ptrTo = t
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user