Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > OT: optimization question

Reply
Thread Tools

OT: optimization question

 
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      05-15-2012
Recently I noticed the last line in an if matched the last
line in an else here:

void
cmwAmbassador::mediateResponse (transactions_t::iterator itr)
{
bool safe_sending = true;
try {
localsendbuf.sock_ = itr->sock;
bool reqResult;
remoteMessages.Receive(cmwBuf, reqResult);


if (reqResult) {
changeDirectory(itr->path.c_str());
::std::vector<File> outputFiles;
remoteMessages.Receive(cmwBuf, outputFiles);

save_lastruntime(itr->filename, itr->time_in_seconds);
safe_sending = false;
localMessages.Marshal(localsendbuf, true);
localsendbuf.Flush();
} else {
::std::string errorMsg;
remoteMessages.Receive(cmwBuf, errorMsg);
safe_sending = false;
localMessages.Marshal(localsendbuf, false, errorMsg);
localsendbuf.Flush();
}
} catch(::std::exception const& ex) {
#ifdef SYSLOG_AVAILABLE
syslog(LOG_ERR, "mediateResponse: %s", ex.what());
#endif
if (safe_sending) {
localMessages.Marshal(localsendbuf, false, ex.what());
localsendbuf.Flush();
}
}
}

.... and I factored it out. I felt certain the new version
would be the same size as it is such a simple thing. I was
surprised when the size of the executable decreased by 88
bytes using gcc 4.7.0 20120314. Using gcc 4.8.0 20120429
the size decreased by 56 bytes. I'm using -O3 in both
cases. This isn't some tricky thing and these are some
recent compilers. Shouldn't compilers be able to handle
this?

Shalom,
Brian
Ebenezer Enterprises
http://webEbenezer.net
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      05-15-2012
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Recently I noticed the last line in an if matched the last
> line in an else here:

[...]
> ... and I factored it out. I felt certain the new version
> would be the same size as it is such a simple thing. I was
> surprised when the size of the executable decreased by 88
> bytes using gcc 4.7.0 20120314. Using gcc 4.8.0 20120429
> the size decreased by 56 bytes. I'm using -O3 in both
> cases. This isn't some tricky thing and these are some
> recent compilers. Shouldn't compilers be able to handle
> this?


They do, at least in part.
Note that your idea of having the same last instruction and the
compilers' idea are not the same (destructors?). Detecting that they
can permute things until there is some common code that can be taken
out of the loop is already much harder.

If you want to understand what compilers do, you'll have to start
looking a bit deeper than the size of the object file (-fdump-tree-all
to start with?).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zero Optimization and Sign Optimization??? Ravikiran C Programming 22 11-24-2008 03:19 AM
A little optimization question: Local var allocation Chris Berg Java 9 12-08-2004 11:40 AM
Variable Optimization Question Bryan Parkoff C++ 3 11-11-2004 11:38 PM
Search engine optimization Question Paul Isaak HTML 4 05-04-2004 08:09 PM
question on NVR optimization cai C++ 0 09-03-2003 01:06 PM



Advertisments