Why my Go program is slow?
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Why my Go program is slow?

  • 0 views
Uploaded on

Go's profiler

Go's profiler

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
0
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Why my Go program is slow? 2014-11-30 稲田
  • 2. INADA Naoki • @methane • KLab Inc. • mobile game company • Python • mysqlclient, PyMySQL, msgpack
  • 3. And I’m gopher • I love Go. It’s fun. It’s more Pythonic than Python! • Explicit is better than implicit. • Simple is better than complex. • Readability counts. • There should be one-- and preferably only one -- obvious way to do it. • Although that way may not be obvious at first unless you're Dutch (Gopher).
  • 4. Today • CPU profiling with pprof • Random notes about Go’s performance. • What I hope Go 1.5~ will have
  • 5. CPU profiling with pprof
  • 6. runtime/pprof • Sampling profiler. • Output data with pprof format. • net/http/pprof provides HTTP API for pprof • github.com/davecheney/profile provice easy API for CLI program.
  • 7. NOTE for Mac • Go’s CPU profiling is not work on Mac • Russ Cox (rsc) explains why: http://research.swtch.com/macpprof • And he provides kernel patch: http://godoc.org/code.google.com/p/rsc/ cmd/pprof_mac_fix • Activity monitor or Instruments provides another sampling profiler
  • 8. pprof command • Included in google perftools • ~Go 1.3 bundles CLI (perl program) • Go 1.4 has reimplement it with Go!
  • 9. Embed net/http/pprof import ( “net/http” _ “net/http/pprof” ) func main() { go http.ListenAndServe(“:6000”, nil) }
  • 10. Let’s use it • top • web (svg) • list and disasm
  • 11. Random notes about Go’s performance
  • 12. Things makes Go slower • GC • memcpy • function call
  • 13. GC • GODEBUG=gctrace=1 • heap profile with pprof • sync.Pool • Provide size hint for slice and map. • make([]int, 0, hint) • make(map[int]int, hint) • GOGC=400
  • 14. memcpy • Choose carefully string or []byte • Especially for constants
  • 15. function call • Go’s calling convention is much slower than C. • No pass by register • All register are volatile • hook for runtime. • Make for loop func. Not body of it. • Bonus: return instead of label.
  • 16. What I hope Go 1.5~ will have • Concurrent GC will be come in Go 1.5! • fastcall for leaf function? • pass by register. • volatile register.