OT: optimization question

Discussion in 'C++' started by woodbrian77@gmail.com, May 15, 2012.

  1. Guest

    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
    , May 15, 2012
    #1
    1. Advertising

  2. Marc Guest

    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?).
    Marc, May 15, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Berg
    Replies:
    9
    Views:
    342
    =?ISO-8859-1?Q?Daniel_Sj=F6blom?=
    Dec 8, 2004
  2. Paul Isaak

    Search engine optimization Question

    Paul Isaak, May 3, 2004, in forum: HTML
    Replies:
    4
    Views:
    430
    Christopher R
    May 4, 2004
  3. cai
    Replies:
    0
    Views:
    469
  4. Bryan Parkoff

    Variable Optimization Question

    Bryan Parkoff, Nov 11, 2004, in forum: C++
    Replies:
    3
    Views:
    375
    David Lindauer
    Nov 11, 2004
  5. Ravikiran

    Zero Optimization and Sign Optimization???

    Ravikiran, Nov 17, 2008, in forum: C Programming
    Replies:
    22
    Views:
    844
    Thad Smith
    Nov 24, 2008
Loading...

Share This Page