Go Performans Rehberi

Go Performans Rehberi

https://gophercon.ist/ için hazırladığım sunum

3a9dc8db324dc41de538f0f48e4bd45d?s=128

Oğuzhan

July 25, 2020
Tweet

Transcript

  1. Oğuzhan Yılmaz Go Performans Rehberi

  2. min. Go 1.14

  3. if > switch

  4. 13.5 ns/op 15.5 ns/op

  5. 12.1 ns/op

  6. strconv > fmt

  7. BenchmarkStrconv-16 19381725 67.5 ns/op 32 B/op 1 allocs/op BenchmarkFmt-16 5839038

    222 ns/op 72 B/op 3 allocs/op 67.5 ns/op
  8. make([]int, 0, 10) > []int{}

  9. BenchmarkMakeSliceWithCap-16 1000000000 0.234 ns/op 0 B/op 0 allocs/op BenchmarkMakeSlice-16 65739

    17390 ns/op 16376 B/op 11 allocs/op 0.234 ns/op
  10. strings.Builder > “a” + “b”

  11. BenchmarkStringBuildNaive-16 6573120 174 ns/op 32 B/op 6 allocs/op BenchmarkStringBuildBuilder-16 19740784

    62.4 ns/op 64 B/op 1 allocs/op 62.4 ns/op
  12. bytes.Replace > strings.Replace bytes Concat > strings Concat bytes Concat

    > strings Join
  13. 70.1 ns/op BenchmarkBytesReplace-4 20000000 70.1 ns/op 32 B/op 1 allocs/op

    BenchmarkStringsReplace-4 10000000 132 ns/op 64 B/op 2 allocs/op
  14. https://github.com/valyala/fasthttp

  15. binary.BigEndian.PutUint32 > binary.Write

  16. 1075 ns/op 113 ns/op

  17. sync.Pool

  18. None
  19. _ = make([]byte, 10<<30)

  20. runtime.MemProfileRate = 0 https://golang.org/pkg/runtime/

  21. syscal.SYS_MMAP

  22. None
  23. map[int]int{} > map[string]int{}

  24. 3 ms/op

  25. json.Marshal(Struct) > json.Marshal(Map)

  26. BenchmarkMarshallStruct-16 4721078 230 ns/op 64 B/op 2 allocs/op BenchmarkMakeSlice-16 1843551

    665 ns/op 512 B/op 10 allocs/op 230 ns/op
  27. Atomic > Mutex

  28. BenchmarkIncrementMutex-16 87149690 12.3 ns/op 0 B/op 0 allocs/op BenchmarkIncrementMutexNoDefer-16 99812758

    12.2 ns/op 0 B/op 0 allocs/op BenchmarkIncrementAtomic-16 286304998 4.19 ns/op 0 B/op 0 allocs/op BenchmarkConcurrentMutex-16 226051 5104 ns/op 16 B/op 1 allocs/op BenchmarkConcurrentMutexNoDefer-16 235743 4941 ns/op 16 B/op 1 allocs/op BenchmarkConcurrentAtomic-16 260210 4635 ns/op 16 B/op 1 allocs/op 4.19 ns/op
  29. 1. https://github.com/dgryski/go-perfbook/blob/master/performance.md 2. https://stephen.sh/posts/quick-go-performance-improvements 3. https://hashrocket.com/blog/posts/go-performance-observations 4. https://gist.github.com/vitalyisaev2/5791627ffc48f10c2fde22c2a5dd32ee