Performance: Prefer prefix operator for non-primitive types #8579

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:Mf1608-perfIter changing 26 files +62 −69
  1. MarcoFalke commented at 4:37 PM on August 24, 2016: member

    No description provided.

  2. Prefer prefix operator for non-primitive types fa18923432
  3. MarcoFalke added the label Refactoring on Aug 24, 2016
  4. MarcoFalke added the label Resource usage on Aug 24, 2016
  5. paveljanik commented at 5:03 PM on August 24, 2016: contributor

    Do you have some numbers? It would be nice to see some benchmarks added first and then comparing ++them with++ 👍

  6. dcousens commented at 11:44 PM on August 24, 2016: contributor

    utACK fa18923, but I really doubt this will be measurable.

  7. MarcoFalke commented at 2:09 PM on August 25, 2016: member

    This was suggested in #7656#discussion-diff-56476755, but apparently for base58 this has 0 effect, the bench binaries are identical. :laughing:

    Some other hunks did not produce identical binaries, so in theory there could be a performance difference. Though, I don't think the performance gain matters in those other places.

  8. MarcoFalke closed this on Aug 25, 2016

  9. MarcoFalke deleted the branch on Aug 25, 2016
  10. UdjinM6 commented at 2:19 PM on August 25, 2016: contributor

    Not sure about specific cases here but in general performance gain could be quite significant: http://stackoverflow.com/a/9519095 Also it might simply be a good practice to use prefix operators by default and postfix only when needed imo.

  11. sipa commented at 2:21 PM on August 25, 2016: member

    In practice I expect this to have very little effect for containers with 'simple' iterators (where the iterator essentially consists of a single pointer). This is the case for std::vector, std::list, std::set, std::map, std::multimap (but not for std::vector<bool> or std::deque). In this case, technically a copy is made before returning, but the compiler will just optimize it away if it is not used.

  12. paveljanik commented at 6:07 PM on August 25, 2016: contributor

    Thank you for testing this Marco!

  13. laanwj commented at 10:36 AM on August 26, 2016: member

    Some other hunks did not produce identical binaries, so in theory there could be a performance difference. Though, I don't think the performance gain matters in those other places.

    Even is changing it retroactively is not deemed worth it, let's try to encourage ++x iso x++ usage in new code, that's pretty uncontroversial.

  14. sipa commented at 10:41 AM on August 26, 2016: member

    Even is changing it retroactively is not deemed worth it, let's try to encourage ++x iso x++ usage in new code, that's pretty uncontroversial.

    Agree. Let's add that to doc/developer-notes.md.

  15. MarcoFalke 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-04-17 06:15 UTC

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