News for hackers. Stuff that matters.
Re:Emiller's Balls-Out Guide to Nginx Module Development by phoboslab on Saturday March 27, 2010 @12:57PM (#1223219)
Is this first code snippet, where the HTTP parser checks for "POST" or "COPY" real? It certainly reads like a joke on how not to optimize your code.

Also, wouldn't it be faster to check all four characters at once with a 32bit compare? And what about branch prediction of the CPU?

Re:Emiller's Balls-Out Guide to Nginx Module Development by ccarpenterg on Saturday March 27, 2010 @02:44PM (#1223397)
What is a 'branch prediction of the CPU'?
Re:Emiller's Balls-Out Guide to Nginx Module Development by alexgartrell on Saturday March 27, 2010 @04:13PM (#1223563)
The CPU has an instruction cache (it reaches out to memory for the series of instructions and grabs a whole bunch at once to be more efficient). When there's a branch (logically, an if statement, a loop, or a goto, or a switch) it has to make a decision about whether or not it should cache the instructions in the if statement or the instructions following the if statement.

Within the linux kernel the macros likely and unlikely are defined so that you can have code of the style

  if(likely(x > 10)) {
    /* These instructions, which probably will be executed,
     * will be cached 
     */
  }

  if(unlikely(ptr == NULL)) {
    /* These instructions, which probably won't need to be 
     * executed, will not be cached
     */
  }
Re:Emiller's Balls-Out Guide to Nginx Module Development by vier on Saturday March 27, 2010 @02:08PM (#1223324)
that's exactly what it's doing