You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
compile my project. use the pprof to get profile info.
found out the characters compare waste almost 26.58s.
I used the string compare has the same problem that's why I separate it to compare head and tail
characters, but it seems does not work either.
(pprof) top 10
Showing nodes accounting for 30.58s, 89.78% of 34.06s total
Dropped 240 nodes (cum <= 0.17s)
Showing top 10 nodes out of 73
flat flat% sum% cum cum%
28.12s 82.56% 82.56% 28.14s 82.62% cos-config/common.findEnv
0.68s 2.00% 84.56% 0.68s 2.00% runtime.futex
0.30s 0.88% 85.44% 0.37s 1.09% syscall.Syscall
0.26s 0.76% 86.20% 0.30s 0.88% runtime.step
0.24s 0.7% 86.91% 0.24s 0.7% runtime.memeqbody
0.23s 0.68% 87.58% 0.23s 0.68% runtime._ExternalCode
0.21s 0.62% 88.20% 0.66s 1.94% runtime.gentraceback
0.19s 0.56% 88.76% 0.40s 1.17% runtime.mallocgc
0.19s 0.56% 89.31% 0.49s 1.44% runtime.pcvalue
0.16s 0.47% 89.78% 0.18s 0.53% runtime.findfunc
(pprof) list cos-config/common.findEnv
Total: 34.06s
ROUTINE ======================== cos-config/common.findEnv in /home/tmd/gostation/src/cos-config/common/config.go
28.12s 28.14s (flat, cum) 82.62% of Total
600ms 600ms 359: for i := 0; i < leng; i++ {
900ms 900ms 360: tName := module.Env[i].EnvName
26.58s 26.58s 361: if tName[0] == head && tName[len(tName)-1] == tail {
40ms 60ms 362: if tName == envName {
Even so, the code you have provided does not look like something amenable to compiler optimization. In particular, comparing the first and last characters is likely to cause needless cache misses and unaligned reads.
Your program is looking for two strings that are equal: if you want the compiler to use its fastest equality check, you should skip the outer check and use tName == envName directly. If the == operation on strings is unexpectedly slow, that is something we can consider optimizing further.
Uh oh!
There was an error while loading. Please reload this page.
go version go1.10 linux/amd64.
ps: online version asked, so not changed to latest release.
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tmd/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/tmd/gostation"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build651618122=/tmp/go-build -gno-record-gcc-switches"
What did you do?
compile my project. use the pprof to get profile info.
found out the characters compare waste almost 26.58s.
I used the string compare has the same problem that's why I separate it to compare head and tail
characters, but it seems does not work either.
(pprof) top 10
Showing nodes accounting for 30.58s, 89.78% of 34.06s total
Dropped 240 nodes (cum <= 0.17s)
Showing top 10 nodes out of 73
flat flat% sum% cum cum%
28.12s 82.56% 82.56% 28.14s 82.62% cos-config/common.findEnv
0.68s 2.00% 84.56% 0.68s 2.00% runtime.futex
0.30s 0.88% 85.44% 0.37s 1.09% syscall.Syscall
0.26s 0.76% 86.20% 0.30s 0.88% runtime.step
0.24s 0.7% 86.91% 0.24s 0.7% runtime.memeqbody
0.23s 0.68% 87.58% 0.23s 0.68% runtime._ExternalCode
0.21s 0.62% 88.20% 0.66s 1.94% runtime.gentraceback
0.19s 0.56% 88.76% 0.40s 1.17% runtime.mallocgc
0.19s 0.56% 89.31% 0.49s 1.44% runtime.pcvalue
0.16s 0.47% 89.78% 0.18s 0.53% runtime.findfunc
(pprof) list cos-config/common.findEnv
Total: 34.06s
ROUTINE ======================== cos-config/common.findEnv in /home/tmd/gostation/src/cos-config/common/config.go
28.12s 28.14s (flat, cum) 82.62% of Total
600ms 600ms 359: for i := 0; i < leng; i++ {
900ms 900ms 360: tName := module.Env[i].EnvName
26.58s 26.58s 361: if tName[0] == head && tName[len(tName)-1] == tail {
40ms 60ms 362: if tName == envName {
pprof disasm output file:
disasm.txt
core code:
What did you expect to see?
low cpu cost
What did you see instead?
high cpu cost
The text was updated successfully, but these errors were encountered: