Enable moving of hashes, uints, outpoints #15336

pull bvbfan wants to merge 1 commits into bitcoin:master from bvbfan:master changing 39 files +401 −292
  1. bvbfan commented at 8:23 AM on February 4, 2019: contributor

    Signed-off-by: Anthony Fieroni bvbfan@abv.bg

    Enabling moving will prevent unwanted copies which can downside performance. Using std::array will help moving semantics to be done, otherwise COutPoint will not be fully movable but it will make exclusive copy on its hashes. base_blob has advantage from std::array by its iterators, base_uint is protected derived from std::array just like C array approach. Overall this patch tends to make improvements in speed and memory overhead.

  2. fanquake added the label Refactoring on Feb 4, 2019
  3. fanquake commented at 9:51 AM on February 4, 2019: member

    This is currently failing 7/10 of the Travis tests.

    Overall this patch tends to make improvements in speed and memory overhead.

    Can you please post your speed and memory benchmarking results.

  4. DrahtBot commented at 10:48 AM on February 4, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15294 ([moveonly] wallet: Extract RipeMd160 by Empact)
    • #14802 (rpc: faster getblockstats using BlockUndo data by FelixWeis)
    • #14734 (fix an undefined behavior in uint::SetHex by kazcw)
    • #14641 (rpc: Add min_conf option to fund transaction calls by promag)
    • #9381 (Remove CWalletTx merging logic from AddToWallet by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  5. bvbfan commented at 3:48 PM on February 4, 2019: contributor

    This is currently failing 7/10 of the Travis tests.

    Can you check what the problem is, it looks like some cache issue?

    Can you please post your speed and memory benchmarking results.

    What results you expects, running bench or perf with / without patch ?

  6. sipa commented at 6:38 PM on February 4, 2019: member

    None of these classes have dynamically allocated memory. A move for them should be identical to a copy. How do you expect that there could be any performance gains?

  7. bvbfan commented at 6:58 PM on February 4, 2019: contributor

    It shouldn't be copy, about me, as i read http://timepp.github.io/doc/cpp14/array.cons.html

  8. sipa commented at 7:20 PM on February 4, 2019: member

    @bvbfan Yes, std::array supports moving, but if the contained type cannot be moved more efficiently than copying, moving the array won't be more efficient than copying it either.

  9. bvbfan commented at 7:55 PM on February 4, 2019: contributor

    It should use less memory, you have right on that integers have practically no difference on copy vs move, but optimization is still relevant to me, since it's base classes which impact on derived one as well.

  10. sipa commented at 7:56 PM on February 4, 2019: member

    @bvbfan I don't see why the compiled code would be different in any way with this change.

  11. practicalswift commented at 9:37 PM on February 4, 2019: contributor

    This PR contains a lot of std::move:s on trivially-copyable types (uint256, uint160 and COutPoint) which don't have any effect.

    Same goes for std::move:s on const reference arguments.

  12. bvbfan commented at 5:29 PM on February 6, 2019: contributor

    I agree, i use to make it by unique_ptr but in many places it's used like

    memcpy(&hash, data, sizeof(hash))
    

    I found some places but not all, some tests segfaults.

  13. gmaxwell commented at 9:08 PM on February 6, 2019: contributor

    It isn't obvious to me how this PR makes a material improvement either to the runtime behaviour or the long term maintenance of the codebase.

  14. bvbfan commented at 4:25 PM on February 7, 2019: contributor

    PR aims to optimize hashes, uints and outpoints by moving. I resolve remaining problems of expecting continuous bytes, in ComputeMerkleRoot double hashing is make by SHA256D64 but in new implementation bytes are not continuous anymore, so i replace it by

     for (std::size_t i = 0, j = 0; i < hashes.size(); i += 2) {
        hashes[j++] = Hash(hashes[i].begin(), hashes[i].end(),
                               hashes[i+1].begin(), hashes[i+1].end());
    }
    

    All tests passes but can it be problematic vs SHA256D64?

  15. bvbfan commented at 7:00 AM on February 9, 2019: contributor

    Rebase to master

  16. Enable moving of hashes, uints, outpoints
    Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
    bfabb16654
  17. bvbfan commented at 7:45 AM on February 10, 2019: contributor

    Sorry for the flood but some tests fails without a reason, it looks like.

  18. gmaxwell commented at 8:36 PM on February 11, 2019: contributor

    NAK. I'm just not seeing a material benefit justifying the expenditure of review efforts.

  19. MarcoFalke commented at 9:19 PM on February 11, 2019: member

    Closing for now. This doesn't compile on appveyor and there seems to be disagreement about whether to do this at all. Probably not worth to put in further effort.

  20. MarcoFalke closed this on Feb 11, 2019

  21. bvbfan commented at 6:30 AM on February 12, 2019: contributor

    @MarcoFalke, you can see at Travis it compile and most tests pass (some weird) not. I'm not familiar with appveyor but it should be something trivial. Edit: I understand that patch became huge, but that was side effect of using memcpy + sizeof + & on object. Also it tries to fix that as well.

  22. DrahtBot locked this on Dec 16, 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-22 06:15 UTC

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