The Boston Diaries

The ongoing saga of a programmer who doesn't live in Boston, nor does he even like Boston, but yet named his weblog/journal “The Boston Diaries.”

Go figure.

Sunday, July 11, 2004

“Hey! What's that code doing there?”

While the __builtin_expect() aspect of GCC didn't work, all the recent profiling I've done on mod_blog (which reminds me, I need to make the current codebase available) did however, bring my attention to BufferIOCtl(), which if you noticed, was one of the top four functions in term of CPU utilization.

int (BufferIOCtl)(const Buffer buf,int cmd, ... )
{
  va_list alist;
  int     rc;
  
  ddt(buf        != NULL);
  ddt(buf->ioreq != NULL);
  ddt(cmd         >   -1);
  
  if (buf == NULL)
    return(ErrorPush(CgiErr,BUFFERIOCTL,BUFERR_NULLPTR,"i",cmd));

  if (buf->ioreq == NULL)
    return(ErrorPush(CgiErr,BUFFERIOCTL,BUFERR_NULLHANDLER,"i",cmd));
  
  va_start(alist,cmd);
  rc = (*buf->ioreq)(buf,cmd,alist);
  va_end(alist);
  return(rc);
}

ddt() is similar to the ANSI C call assert(), which basically states a condition that should exist (and if that condition isn't met, the program aborts—this action can be turned off for production code; it's meant for debugging). But you'll notice that the code first checks to see if buf is not NULL within ddt(), then the first thing it does is check to see if buff is NULL.

It shouldn't be NULL to begin with.

The same for the tests of buf->ioreq. When I removed the extraneous code:

int (BufferIOCtl)(const Buffer buf,int cmd, ... )
{
  va_list alist;
  int     rc;
  
  ddt(buf        != NULL);
  ddt(buf->ioreq != NULL);
  ddt(cmd        >  -1);
  
  va_start(alist,cmd);
  rc = (*buf->ioreq)(buf,cmd,alist);
  va_end(alist);
  return(rc);
}

The runtime of BufferIOCtl() dropped to 1/3 the original time.

Not much in the grand scheme of things, but just goes to show you how expensive extraneous if statements can be. Especially if it's called 6,646,086 times.

Obligatory Picture

An abstract representation of where you're coming from]

Obligatory Contact Info

Obligatory Feeds

Obligatory Links

Obligatory Miscellaneous

Obligatory AI Disclaimer

No AI was used in the making of this site, unless otherwise noted.

You have my permission to link freely to any entry here. Go ahead, I won't bite. I promise.

The dates are the permanent links to that day's entries (or entry, if there is only one entry). The titles are the permanent links to that entry only. The format for the links are simple: Start with the base link for this site: https://boston.conman.org/, then add the date you are interested in, say 2000/08/01, so that would make the final URL:

https://boston.conman.org/2000/08/01

You can also specify the entire month by leaving off the day portion. You can even select an arbitrary portion of time.

You may also note subtle shading of the links and that's intentional: the “closer” the link is (relative to the page) the “brighter” it appears. It's an experiment in using color shading to denote the distance a link is from here. If you don't notice it, don't worry; it's not all that important.

It is assumed that every brand name, slogan, corporate name, symbol, design element, et cetera mentioned in these pages is a protected and/or trademarked entity, the sole property of its owner(s), and acknowledgement of this status is implied.

Copyright © 1999-2024 by Sean Conner. All Rights Reserved.