Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overview of slow unit tests #10026

Closed
laanwj opened this issue Mar 18, 2017 · 27 comments
Closed

Overview of slow unit tests #10026

laanwj opened this issue Mar 18, 2017 · 27 comments
Labels

Comments

@laanwj
Copy link
Member

laanwj commented Mar 18, 2017

At last IRC meeting we've discussed trying to speed up the unit tests, as they've become much too slow.
For this purpose I've run test_bitcoin --log_level=test_suite and picked out the slowest from the list.

The top 20 is (updated 2018-04-14 by @lucash-dev):

Test Time (μs)
test_big_witness_transaction 39133014
test_CheckQueue_Correct_Random 14808019
knapsack_solver_test 9304171
checkinputs_test 6370348
CreateNewBlock_validity 6105558
test_CheckQueue_Memory 4230330
versionbits_test 3835090
coins_cache_simulation_test 3205869
updatecoins_simulation_test 2499840
merkle_test 2391688
rescan 1900315
SelectCoins_test 1731901
passphrase 1730167
ListCoins 1689793
test_CheckQueue_Catches_Failure 1563869
test_CheckQueue_UniqueCheck 1521864
PrevectorTestInt 1409636
test_CheckQueue_Correct_Max 1401687
bnb_search_test 1147974
cuckoocache_generations 978637

I think (open for discussion, of course) it is unreasonable for a unit test case to take more than ~1s (mind you, we have 242 of them, so each test is supposed to be quick) so we should take a look at each of these up to merkle_test.

It could be as simple in some cases as getting rid of (reasonably heavy) BOOST_* tests in inner loops, moving the checks up to a higher level.

Edit: I added the script to create this table to maintainer-tools: https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/master/unittest-statistics.py

@laanwj laanwj added the Tests label Mar 18, 2017
@paveljanik
Copy link
Contributor

The first one is

/** Test that random numbers of checks are correct
 */
BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random)
{
    std::vector<size_t> range;
    range.reserve(100000/1000);
    for (size_t i = 2; i < 100000; i += std::max((size_t)1, (size_t)GetRand(std::min((size_t)1000, ((size_t)100000) - i))))
        range.push_back(i);
    Correct_Queue_range(range);
}

By simply removing GetRand call, the time is reduced from 33s to 15s here. Ie. the test spends ~half of the time in generating random numbers.

@paveljanik
Copy link
Contributor

test_big_witness_transaction is signing 4500 inputs and it takes time.

@NicolasDorier
Copy link
Contributor

test_big_witness_transaction was a test I wrote for checking if the CachedHashes of segwit was thread safe. What takes time is the signing of inputs. I think a better idea is to hard code the transaction. But I think it would be kind of big.

@JeremyRubin
Copy link
Contributor

Sorry for writing so many of the slow tests!

Getting rid of GetRand from the CheckQueue tests is 100% fine; and should speed things up ( @kallewoof brought that up in review, but I didn't think it would be a huge time sink).

The cuckoocache_generations test is parametrized by:

    const uint32_t BLOCK_SIZE = 10000;
    // We expect window size 60 to perform reasonably given that each epoch
    // stores 45% of the cache size (~472k).
    const uint32_t WINDOW_SIZE = 60;
    const uint32_t POP_AMOUNT = (BLOCK_SIZE / WINDOW_SIZE) / 2;
    const double load = 10;
    const size_t megabytes = 32;
    const size_t bytes = megabytes * (1 << 20);
    const uint32_t n_insert = static_cast<uint32_t>(load * (bytes / sizeof(uint256)));

picking smaller constants should be fine (although increases the potential variance, e.g., likelihood of deterministic failure). The rest of the cuckoocache_tests are also parametric (e.g., just a size in MB and a hit rate lower bound) so can be easily adjusted. I initially picked a size to match the default parameter, but we could scale down to, say 4mb or 2mb.

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Mar 23, 2017

would writing my transaction with 4500 input hard coded be a problem ? I can do it but unsure if it is the right way.

@laanwj
Copy link
Member Author

laanwj commented Mar 23, 2017

@NicolasDorier just how large would that data be? Very large (multi-MB) files of test data likely shouldn't be part of the repository.

@NicolasDorier
Copy link
Contributor

@laanwj around 1 MB.

@JeremyRubin
Copy link
Contributor

I would also note that checkqueue tests should improve a lot under #9938, I need to clean up that PR a bit though in accordance to Matt's feedback.

@laanwj
Copy link
Member Author

laanwj commented Apr 2, 2017

Updated for #10128

sipa added a commit that referenced this issue Oct 12, 2017
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in #9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to #10026 and some feedback on #9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ #10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see #9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
@CinchBlue
Copy link

Do you guys think we could get an update on this issue? I think that the top unit test_CheckQueue_Correct_Random is ultimately using a FastRandomContext which seems to be doing a lot of extra sampling for the random values -- the procedure retries every time it fails to generate a bit sequence in a certain bit range. Would there be a more efficient way to pre-set the range, customize the random number generator to generate uniformly-distributed values in this bit range so that no retries are not necessary. Or, could the slowdown be happening in the verification phase?

@maflcko
Copy link
Member

maflcko commented Apr 11, 2018

Marking "up for grabs" to see what unit tests are still slow and master and figure out how to speed them up.

https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/master/unittest-statistics.py might come in hnady.

@jamesob
Copy link
Contributor

jamesob commented Apr 11, 2018

Should we add a "good first issue" label to this?

@lucash-dev
Copy link
Contributor

Hi, I would like to work on this as my first issue.

@maflcko
Copy link
Member

maflcko commented Apr 13, 2018 via email

@lucash-dev
Copy link
Contributor

lucash-dev commented Apr 14, 2018

Updated table (as of #11200)
Can't compare numbers directly with previous ones, since it's a different setup, but the ordering should be consistent.

(pasted into OP)

test_big_witness_transaction and test_CheckQueue_Correct_Random are still the most time consuming, so I'll focus on these.

@laanwj
Copy link
Member Author

laanwj commented Apr 14, 2018

@lucash-dev Thanks! Moved your table into the OP.

@lucash-dev
Copy link
Contributor

The https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/master/unittest-statistics.py script was mixing up test suite and test case statistics (presumably due to some change in how test_bitcoinoutput is generated).

Created an issue and a PR in the maintainer tools repo.

@lucash-dev
Copy link
Contributor

test_big_witness_transaction is spending most of time converting CMutableTransaction to CTransaction, which involves recalculating hashes. That's because each call to SignSignature does the conversion again for the whole transaction.

This means the time complexity for providing witnesses for the 4500 inputs has a O(n2) component.

Changing the test to use lower level functions ProduceSignature and UpdateTransaction, and reusing the same CTransaction in all iterations, reduces run time in about 70%.

Created a WIP PR (will add improvements to other tests to this PR).

I'm just wondering if that is not rather a bug in SignSignature. Should it create a new CTransaction every time it's called?

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jan 12, 2020
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in bitcoin#9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to bitcoin#10026 and some feedback on bitcoin#9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ bitcoin#10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see bitcoin#9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jan 12, 2020
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in bitcoin#9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to bitcoin#10026 and some feedback on bitcoin#9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ bitcoin#10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see bitcoin#9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jan 12, 2020
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in bitcoin#9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to bitcoin#10026 and some feedback on bitcoin#9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ bitcoin#10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see bitcoin#9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jan 12, 2020
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in bitcoin#9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to bitcoin#10026 and some feedback on bitcoin#9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ bitcoin#10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see bitcoin#9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jan 12, 2020
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in bitcoin#9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to bitcoin#10026 and some feedback on bitcoin#9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ bitcoin#10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see bitcoin#9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jan 12, 2020
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in bitcoin#9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to bitcoin#10026 and some feedback on bitcoin#9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ bitcoin#10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see bitcoin#9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jan 16, 2020
8c2f4b8 Expose more parallelism with relaxed atomics (suggested in bitcoin#9938). Fix a test to check the exclusive or of two properties rather than just or. (Jeremy Rubin)

Pull request description:

  This PR is in response to bitcoin#10026 and some feedback on bitcoin#9938.

  ~Locally, all the checkqueue tests ran 3.2X faster on my machine. The worst offender, `test_CheckQueue_Correct_Random` ran 3.4X faster.~

  1. ~Removes `GetRand()` and replaces it with a single deterministic FastRandomContext instance.~ bitcoin#10321 replicated this

  1. Exposes more parallelism with relaxed atomics, increasing chance of catching a bug. This does not change performance on my machine.

  1. Makes one test case more restrictive (xor instead of or, see bitcoin#9938).

Tree-SHA512: a59dfbee0273c713525a130dfedc1c7ff26f50c2aaca1e94ef5d759b1d6ea6338ffbd97f863b9f6209750d8a788a15fa8ae1bf26774ed2473c520811337e6b00
@maflcko
Copy link
Member

maflcko commented Apr 27, 2020

The feature request didn't seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open issues.

Closing due to lack of interest. Pull requests with improvements are always welcome.

@maflcko maflcko closed this as completed Apr 27, 2020
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 19, 2021
…nSignature

6b8b63a Generic TransactionSignatureCreator works with both CTransaction and CMutableTransaction (Martin Ankerl)

Pull request description:

  Refactored `TransactionSignatureCreator` into a templated `GenericTransactionSignatureCreator` that works with both `CMutableTransaction` and `CTransaction`.

  The advantage is that now in `SignSignature`, the `MutableTransactionSignatureCreator` can now operate directly with the `CMutableTransaction` without the need to copy the data into a `CTransaction`.

  Running all unit tests brings a very noticable speedup on my machine:

      48.4 sec before this change
      36.4 sec with this change
      --------
      12.0 seconds saved

  running only `--run_test=transaction_tests/test_big_witness_transaction`:

      16.7 sec before this change
       5.9 sec with this change
      --------
      10.8 seconds saved

  This relates to my first attempt with the const_cast hack bitcoin#13202, and to the slow unit test issue bitcoin#10026.

  Also see bitcoin#13050 which modifies the tests but not the production code (like this PR) to get a speedup.

Tree-SHA512: 2cff0e9699f484f26120a40e431a24c8bc8f9e780fd89cb0ecf20c5be3eab6c43f9c359cde244abd9f3620d06c7c354e3b9dd3da41fa2ca1ac1e09386fea25fb
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 19, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 24, 2021
…nSignature

6b8b63a Generic TransactionSignatureCreator works with both CTransaction and CMutableTransaction (Martin Ankerl)

Pull request description:

  Refactored `TransactionSignatureCreator` into a templated `GenericTransactionSignatureCreator` that works with both `CMutableTransaction` and `CTransaction`.

  The advantage is that now in `SignSignature`, the `MutableTransactionSignatureCreator` can now operate directly with the `CMutableTransaction` without the need to copy the data into a `CTransaction`.

  Running all unit tests brings a very noticable speedup on my machine:

      48.4 sec before this change
      36.4 sec with this change
      --------
      12.0 seconds saved

  running only `--run_test=transaction_tests/test_big_witness_transaction`:

      16.7 sec before this change
       5.9 sec with this change
      --------
      10.8 seconds saved

  This relates to my first attempt with the const_cast hack bitcoin#13202, and to the slow unit test issue bitcoin#10026.

  Also see bitcoin#13050 which modifies the tests but not the production code (like this PR) to get a speedup.

Tree-SHA512: 2cff0e9699f484f26120a40e431a24c8bc8f9e780fd89cb0ecf20c5be3eab6c43f9c359cde244abd9f3620d06c7c354e3b9dd3da41fa2ca1ac1e09386fea25fb
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 24, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 26, 2021
…nSignature

6b8b63a Generic TransactionSignatureCreator works with both CTransaction and CMutableTransaction (Martin Ankerl)

Pull request description:

  Refactored `TransactionSignatureCreator` into a templated `GenericTransactionSignatureCreator` that works with both `CMutableTransaction` and `CTransaction`.

  The advantage is that now in `SignSignature`, the `MutableTransactionSignatureCreator` can now operate directly with the `CMutableTransaction` without the need to copy the data into a `CTransaction`.

  Running all unit tests brings a very noticable speedup on my machine:

      48.4 sec before this change
      36.4 sec with this change
      --------
      12.0 seconds saved

  running only `--run_test=transaction_tests/test_big_witness_transaction`:

      16.7 sec before this change
       5.9 sec with this change
      --------
      10.8 seconds saved

  This relates to my first attempt with the const_cast hack bitcoin#13202, and to the slow unit test issue bitcoin#10026.

  Also see bitcoin#13050 which modifies the tests but not the production code (like this PR) to get a speedup.

Tree-SHA512: 2cff0e9699f484f26120a40e431a24c8bc8f9e780fd89cb0ecf20c5be3eab6c43f9c359cde244abd9f3620d06c7c354e3b9dd3da41fa2ca1ac1e09386fea25fb
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 26, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 26, 2021
…nSignature

6b8b63a Generic TransactionSignatureCreator works with both CTransaction and CMutableTransaction (Martin Ankerl)

Pull request description:

  Refactored `TransactionSignatureCreator` into a templated `GenericTransactionSignatureCreator` that works with both `CMutableTransaction` and `CTransaction`.

  The advantage is that now in `SignSignature`, the `MutableTransactionSignatureCreator` can now operate directly with the `CMutableTransaction` without the need to copy the data into a `CTransaction`.

  Running all unit tests brings a very noticable speedup on my machine:

      48.4 sec before this change
      36.4 sec with this change
      --------
      12.0 seconds saved

  running only `--run_test=transaction_tests/test_big_witness_transaction`:

      16.7 sec before this change
       5.9 sec with this change
      --------
      10.8 seconds saved

  This relates to my first attempt with the const_cast hack bitcoin#13202, and to the slow unit test issue bitcoin#10026.

  Also see bitcoin#13050 which modifies the tests but not the production code (like this PR) to get a speedup.

Tree-SHA512: 2cff0e9699f484f26120a40e431a24c8bc8f9e780fd89cb0ecf20c5be3eab6c43f9c359cde244abd9f3620d06c7c354e3b9dd3da41fa2ca1ac1e09386fea25fb
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 26, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jun 27, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jun 28, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jun 28, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 28, 2021
…nSignature

6b8b63a Generic TransactionSignatureCreator works with both CTransaction and CMutableTransaction (Martin Ankerl)

Pull request description:

  Refactored `TransactionSignatureCreator` into a templated `GenericTransactionSignatureCreator` that works with both `CMutableTransaction` and `CTransaction`.

  The advantage is that now in `SignSignature`, the `MutableTransactionSignatureCreator` can now operate directly with the `CMutableTransaction` without the need to copy the data into a `CTransaction`.

  Running all unit tests brings a very noticable speedup on my machine:

      48.4 sec before this change
      36.4 sec with this change
      --------
      12.0 seconds saved

  running only `--run_test=transaction_tests/test_big_witness_transaction`:

      16.7 sec before this change
       5.9 sec with this change
      --------
      10.8 seconds saved

  This relates to my first attempt with the const_cast hack bitcoin#13202, and to the slow unit test issue bitcoin#10026.

  Also see bitcoin#13050 which modifies the tests but not the production code (like this PR) to get a speedup.

Tree-SHA512: 2cff0e9699f484f26120a40e431a24c8bc8f9e780fd89cb0ecf20c5be3eab6c43f9c359cde244abd9f3620d06c7c354e3b9dd3da41fa2ca1ac1e09386fea25fb
UdjinM6 pushed a commit to UdjinM6/dash that referenced this issue Jun 28, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jun 29, 2021
…reusing of CTransaction.

ebebedc speed up of tx_validationcache_tests by reusing of CTransaction. (lucash.dev@gmail.com)

Pull request description:

  The code was converting CMutableTransaction to CTransaction multiple times, which implies recalculating the hash multiple times. This commit fixes this by reusing a single CTransaction.

  Run-time results:
  ```
  Before:  6.7s
  After: 5.5s
  --------------
  Saved: 1.2s
  ```
  This PR was split from bitcoin#13050. Also, see bitcoin#10026.

Tree-SHA512: 61fb81972a08299085a7d3d0060485b265aefc7a4f82ab548e5f94371c8643cfb97bf0ef34f4e1211bf853d0217fa1c3338e4117f36fda1b37d203f690e86d60
Munkybooty pushed a commit to Munkybooty/dash that referenced this issue Jul 7, 2021
…reating wallet 100 times.

a679109 Speed up knapsack_solver_test by not recreating wallet 100 times. (lucash.dev@gmail.com)

Pull request description:

  Optimization of `knapsack_solver_test`by moving an expensive wallet creation to outside a 100x for loop.

  On my (slow) machine:

  ```
  before:        9.8s
  after:         6.2s
  --------------------
  saved:         3.6s (36%)
  ```

  This PR was split from bitcoin#13050. Also see bitcoin#10026.

Tree-SHA512: bde1a856b5f076a5845e14d1a924855c8c91742c3139b47903081289b21d01fef6f2d1fd8947058728a57de56f877bab3866af8cd1d25ba2daa44411752cdb2f
Munkybooty pushed a commit to Munkybooty/dash that referenced this issue Jul 8, 2021
…reating wallet 100 times.

a679109 Speed up knapsack_solver_test by not recreating wallet 100 times. (lucash.dev@gmail.com)

Pull request description:

  Optimization of `knapsack_solver_test`by moving an expensive wallet creation to outside a 100x for loop.

  On my (slow) machine:

  ```
  before:        9.8s
  after:         6.2s
  --------------------
  saved:         3.6s (36%)
  ```

  This PR was split from bitcoin#13050. Also see bitcoin#10026.

Tree-SHA512: bde1a856b5f076a5845e14d1a924855c8c91742c3139b47903081289b21d01fef6f2d1fd8947058728a57de56f877bab3866af8cd1d25ba2daa44411752cdb2f
Munkybooty pushed a commit to Munkybooty/dash that referenced this issue Jul 9, 2021
…reating wallet 100 times.

a679109 Speed up knapsack_solver_test by not recreating wallet 100 times. (lucash.dev@gmail.com)

Pull request description:

  Optimization of `knapsack_solver_test`by moving an expensive wallet creation to outside a 100x for loop.

  On my (slow) machine:

  ```
  before:        9.8s
  after:         6.2s
  --------------------
  saved:         3.6s (36%)
  ```

  This PR was split from bitcoin#13050. Also see bitcoin#10026.

Tree-SHA512: bde1a856b5f076a5845e14d1a924855c8c91742c3139b47903081289b21d01fef6f2d1fd8947058728a57de56f877bab3866af8cd1d25ba2daa44411752cdb2f
Munkybooty pushed a commit to Munkybooty/dash that referenced this issue Jul 11, 2021
…reating wallet 100 times.

a679109 Speed up knapsack_solver_test by not recreating wallet 100 times. (lucash.dev@gmail.com)

Pull request description:

  Optimization of `knapsack_solver_test`by moving an expensive wallet creation to outside a 100x for loop.

  On my (slow) machine:

  ```
  before:        9.8s
  after:         6.2s
  --------------------
  saved:         3.6s (36%)
  ```

  This PR was split from bitcoin#13050. Also see bitcoin#10026.

Tree-SHA512: bde1a856b5f076a5845e14d1a924855c8c91742c3139b47903081289b21d01fef6f2d1fd8947058728a57de56f877bab3866af8cd1d25ba2daa44411752cdb2f
maflcko pushed a commit that referenced this issue Jul 24, 2021
…ache_tests

c3e111a Reduced number of validations in `tx_validationcache_tests` to keep the run time reasonable. (lucash-dev)

Pull request description:

  Following a suggestion in the comments, changed `ValidateCheckInputsForAllFlags` from testing all possible flag combinations to testing a random subset. Also created a new enum constant for the highest flag, so that this test doesn’t keep testing an incomplete subset in case a new flag is added.

  Timing for `checkinputs_test`:
  ```
  Before:   6.8s
  After:    3.7s
  ----------------
  Saved:    3.1s (45%)
  ```

  This PR was split from #13050. Also see #10026.

ACKs for top commit:
  leonardojobim:
    tACK c3e111a.
  kallewoof:
    ACK c3e111a
  theStack:
    re-ACK c3e111a

Tree-SHA512: bef49645bdd4f61ec73cc77a9f028b95d9856db9446d2e7fc9a48867a6f0e94c2c9f150cb771a30fe852db0efb0a1bd15d38b00d712651793ccb59ff6157a7b4
sidhujag pushed a commit to syscoin/syscoin that referenced this issue Jul 28, 2021
…dationcache_tests

c3e111a Reduced number of validations in `tx_validationcache_tests` to keep the run time reasonable. (lucash-dev)

Pull request description:

  Following a suggestion in the comments, changed `ValidateCheckInputsForAllFlags` from testing all possible flag combinations to testing a random subset. Also created a new enum constant for the highest flag, so that this test doesn’t keep testing an incomplete subset in case a new flag is added.

  Timing for `checkinputs_test`:
  ```
  Before:   6.8s
  After:    3.7s
  ----------------
  Saved:    3.1s (45%)
  ```

  This PR was split from bitcoin#13050. Also see bitcoin#10026.

ACKs for top commit:
  leonardojobim:
    tACK bitcoin@c3e111a.
  kallewoof:
    ACK c3e111a
  theStack:
    re-ACK c3e111a

Tree-SHA512: bef49645bdd4f61ec73cc77a9f028b95d9856db9446d2e7fc9a48867a6f0e94c2c9f150cb771a30fe852db0efb0a1bd15d38b00d712651793ccb59ff6157a7b4
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants