Apply More Effective C++ item 6 advice #3054

pull lano1106 wants to merge 1 commits into bitcoin:master from lano1106:more_effective_cpp_item6 changing 10 files +36 −30
  1. lano1106 commented at 10:52 PM on October 4, 2013: contributor

    Basically that means to prefer prefix increment over postfix ones As the latter produce temporary objects.

    Signed-off-by: Olivier Langlois olivier@olivierlanglois.net

  2. Apply More Effective C++ item 6 advice
    Basically that means to prefer prefix increment over postfix ones
    As the latter produce temporary objects.
    
    Signed-off-by: Olivier Langlois <olivier@olivierlanglois.net>
    c2b705f0ce
  3. BitcoinPullTester commented at 11:20 PM on October 4, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/c2b705f0ce0a1c51f71db62b757d43f752499e8a for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  4. gavinandresen commented at 11:53 PM on October 4, 2013: contributor

    NACK from me. Compilers are very good at optimizing away creation of temporary objects, and I'm against this kind of "worry about micro-optimizations that used to matter in some compiler somewhere but aren't relevant any more" change.

  5. lano1106 commented at 6:10 AM on October 5, 2013: contributor

    g++ 4.8.1 isn't that good then as I have verified that the generated binaries after the patch were smaller.

    I have seen computation programs execution time reduced from 2 hours to 25 mins by doing just that.

    Granted bitcoin is probably more io bounded than it is doing heavy STL iterations but why doing gratuitous pessimization when a better form that does not affect readability or code complexity exist is offered?

    I want to contribute to your project and before taking on more ambitious tasks, I want to slowly gain your trust by doing small improvements.

    Greetings,

  6. gavinandresen commented at 6:52 AM on October 5, 2013: contributor

    Our bottleneck is testing and review, so the best way to slowly gain our trust is to help test and review existing pull requests, before adding to the general workload by submitting small improvements that must still be tested and reviewed.

    RE: generated binaries are smaller: how much smaller for release builds? Eleven bytes or eleven-hundred K? Significantly smaller binaries would be a good reason to accept this patch (and should have been mentioned at the start as a reason to accept).

  7. gmaxwell commented at 3:07 PM on October 5, 2013: contributor

    I have seen computation programs execution time reduced from 2 hours to 25 mins by doing just that.

    And the improvement here was?

  8. lano1106 commented at 5:12 AM on October 6, 2013: contributor

    Gavin,

    We are talking about 10KB on the 64-bits build but I think that you were right and I must say that this is before stripping the exec. After stripping they have the same size.

    I have explored the question further with these small test program

    lano1106@Wailaba2 ~/dev/test :( $ cat pre.cpp #include <iostream> #include <map>

    int main( int argc, char *argv[] ) { std::map<int,int> m;

    for( int i = 0; i < 10; ++i )
        m[i] = i;
    
    for( auto it = m.begin(); it != m.end(); ++it )
    {
        std::cout << it->first << ':' << it->second << '\n';
    }
    
    return 0;
    

    }

    lano1106@Wailaba2 ~/dev/test $ cat post.cpp #include <iostream> #include <map>

    int main( int argc, char *argv[] ) { std::map<int,int> m;

    for( int i = 0; i < 10; ++i )
        m[i] = i;
    
    for( auto it = m.begin(); it != m.end(); it++ )
    {
        std::cout << it->first << ':' << it->second << '\n';
    }
    
    return 0;
    

    }

    lano1106@Wailaba2 ~/dev/test $ g++ -S -std=c++11 pre.cpp lano1106@Wailaba2 ~/dev/test $ g++ -S -std=c++11 post.cpp lano1106@Wailaba2 ~/dev/test $ diff pre.s post.s

    The output is significantly different but as soon as you put a -O switch the difference goes away.

    I have learn something from this discussion.

    Thanks

  9. gavinandresen closed this on Oct 6, 2013

  10. laanwj commented at 7:33 AM on October 6, 2013: member

    We're not a big fan of commits that make changes all over the place. If you want to optimize, it's better to pick a function that's used a lot, benchmark it, then re-benchmark it after the changes.

  11. luke-jr commented at 10:34 PM on February 20, 2014: member

    @gavinandresen I'm pretty sure it would violate the C++ spec to optimise away postfix copying. @lano1106 Gaining trust should not be a goal here. Every change must be carefully reviewed, tested, and audited, regardless of how much "trust" anyone has for the author.

  12. Bushstar referenced this in commit f2443709b3 on Apr 8, 2020
  13. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me