CTxMemPool: encapsulate map[Next]Tx, by adding method copyFinal() #1489

pull jgarzik wants to merge 1 commits into bitcoin:master from jgarzik:mempool-encap changing 2 files +28 −8
  1. jgarzik commented at 3:58 PM on June 20, 2012: contributor

    This [re]moves a lock and a direct mempool.mapTx access, by copying the TX memory pool contents into a temporary vector, for use when building a new block inside CreateNewBlock().

    In addition to holding CTxMemPool::cs for a shorter amount of time, this makes it easier to parallelize CreateNewBlock() -- something already done in widely circulating miner-pool patches.

    The cost: memcopying the TX memory pool at each CreateNewBlock() invocation (each getwork / getmemorypool new-work request).

  2. CTxMemPool: encapsulate map[Next]Tx, by adding method copyFinal()
    This [re]moves a lock and a direct mempool.mapTx access, by copying
    the TX memory pool contents into a temporary vector, for use when
    building a new block inside CreateNewBlock().
    
    In addition to holding CTxMemPool::cs for a shorter amount of time,
    this makes it easier to parallelize CreateNewBlock() -- something
    already done in widely circulating miner-pool patches.
    
    The cost: memcopying the TX memory pool at each CreateNewBlock()
    invocation (each getwork / getmemorypool new-work request).
    7137e89561
  3. luke-jr commented at 9:23 PM on June 21, 2012: member

    Neither getwork nor getmemorypool should be even trying to call CreateNewBlock in parallel... they cache its results.

    (Not that there's anything wrong with this optimization.)

  4. jgarzik commented at 10:18 PM on June 21, 2012: contributor

    The former does not follow from the latter.

  5. luke-jr commented at 10:49 PM on June 21, 2012: member

    @jgarzik There should be a mutex on the cache, so I'm not sure how you'd get into CreateNewBlock concurrently. Unless you're thinking of getwork and getmemorypool at the same time, but I can't think of any reason to support that...

  6. luke-jr commented at 11:50 PM on June 21, 2012: member

    This also conflicts with #1240 as-is: can copyFinal return map<uint256, CTransaction> instead?

  7. jgarzik commented at 11:51 PM on June 21, 2012: contributor

    The cache is only accessed when you think it would be accessed: quickly upon read, or after building a block. The cache's lock need not be held while building a new block.

  8. luke-jr commented at 12:00 AM on June 22, 2012: member

    IMO, it's better to hold it while building a new block: instead of having 20 parallel CreateNewBlock running at potentially 1/20th the speed each for no benefit, you get a single one that finishes in 1/20th the time and the rest use the cached value from...

  9. jgarzik commented at 3:51 PM on June 27, 2012: contributor

    Closing, not enough interest. It remains a valid technique if we want to explore this avenue in the future.

  10. jgarzik closed this on Jun 27, 2012

  11. jgarzik deleted the branch on Aug 24, 2014
  12. suprnurd referenced this in commit 109c5fd1d8 on Dec 5, 2017
  13. lateminer referenced this in commit 7f1bc976b9 on Jan 22, 2019
  14. lateminer referenced this in commit e4d6c26f61 on May 6, 2020
  15. DrahtBot locked this on Sep 8, 2021
Contributors

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-20 00:16 UTC

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