detect which objects are global in a simpler way
To detect if an object is global, our previous code did: obj.Pkg().Scope().Lookup(obj.Name()) == obj However, that Lookup call is unnecessary. It is a map lookup, which is cheap, but not free. Instead, we can compare the scopes directly: obj.Pkg().Scope() == obj.Parent() While here, reuse the calls to obj.Pkg(), and avoid using fmt.Sprintf in this hot path. Looked here since perf on Linux with a garble build reports that we spend about 2.6% of CPU time in recordedObjectString. Overall provides a very minor improvement: name old time/op new time/op delta Build-16 21.8s ± 1% 21.7s ± 0% ~ (p=0.200 n=4+4) name old bin-B new bin-B delta Build-16 5.67M ± 0% 5.67M ± 0% ~ (all equal) name old cached-time/op new cached-time/op delta Build-16 734ms ± 3% 722ms ± 3% ~ (p=0.486 n=4+4) name old mallocs/op new mallocs/op delta Build-16 25.0M ± 0% 24.7M ± 0% -1.28% (p=0.029 n=4+4) name old sys-time/op new sys-time/op delta Build-16 17.0s ± 1% 16.8s ± 1% ~ (p=0.200 n=4+4)pull/643/head
parent
8ea0708bca
commit
7e95fcf1cb
Loading…
Reference in New Issue