0

I'm trying to optimize some parts of my Go application and profiling the CPU with pprof I got some numbers that, first of all, surprise me.

pprof snapshot

It feels weird to me that lines 81, 82, and 83 are one of the slower ones. They are only applying bitwise operations on some variables. value, upper, and lower are all of type byte.

What I am missing here? I don't see how I can optimize those operations. Am I missing understanding these numbers?

Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
Pherrymason
  • 7,835
  • 8
  • 39
  • 57
  • 5
    a profile is not a list of absolute execution times, it's a histogram of samples taken during execution. There's not much to be learned from looking at single lines like those, unless maybe you are also comparing the machine code being executed. – JimB Jul 19 '22 at 18:20
  • 4
    Those three lines are inside nested loops, so they get executed many times. The read isn't how long it takes to execute that line once, it's how much time in total is spent on that line in the samples. – Adrian Jul 19 '22 at 18:43
  • 2
    In an ideal world those "mathsy" instructions make up 100% of the CPU profile (for programs that are primarily concerned with computing things anyway, which seems to be the case here). That would mean that there is zero overhead in your program (such as memory management or I/O). It'd be more concerning if the program _didn't_ spend much time there. – Peter Jul 19 '22 at 23:02
  • 2
    Just realized that my last comment can be taken the wrong way. It doesn't mean that you shouldn't look at those lines and think about if those are the fastest possible operations to get the job done. I was just meaning to say that it is not a goal to get every line towards 0 ms (then your program would do nothing at all!). – Peter Jul 19 '22 at 23:10

0 Answers0