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

test: Removed implicit CTransaction constructor calls from tests and benchmarks. #14908

Conversation

Projects
None yet
6 participants
@lucash-dev
Copy link
Contributor

commented Dec 10, 2018

This PR was split from #14906 and is a prerequisite for it.
It updates tests and benchmarks, removing all implicit calls to CTransaction(CMutableTransaction&) constructors. This will make possible making the constructor explicit in the next PR.
The original rationale for making the constructor explicit:

  • Conversion constructors should not be explicit unless there's a strong reason for it (in the opinion of, for example, https://google.github.io/styleguide/cppguide.html, and https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ro-conversion. Let me know your take on this).
  • This particular conversion is very costly -- it implies a serialization plus hash of the transaction.
  • Even though CTransaction and CMutableTransaction represent the same data, they have very different use cases and performance properties.
  • Making it explicit allows for easier reasoning of performance trade-offs.
  • There has been previous performance issues caused by unneeded use of this implicit conversion.
  • This PR creates a map for places to look for possible refactoring and performance gains (this benefit still holds if the PR is not merged).
@DrahtBot

This comment has been minimized.

Copy link
Contributor

commented Dec 10, 2018

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #14935 (tests: Test for expected return values when calling functions returning a success code by practicalswift)
  • #14505 (Make single parameter constructors explicit (C++11). Add explicit constructor linter. by practicalswift)
  • #13868 (Remove unused fScriptChecks parameter from CheckInputs by Empact)
  • #13525 (Report reason inputs are nonstandard from AreInputsStandard by Empact)

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.

src/bench/ccoins_caching.cpp Outdated
@@ -76,10 +76,11 @@ static void CCoinsCaching(benchmark::State& state)
t1.vout[0].scriptPubKey << OP_1;

// Benchmark.
CTransaction cTx(t1);

This comment has been minimized.

Copy link
@MarcoFalke

MarcoFalke Dec 10, 2018

Member

can be const and shout be snake case? tx_1?

src/bench/mempool_eviction.cpp Outdated
@@ -127,7 +128,7 @@ static void MempoolEviction(benchmark::State& state)
AddTx(tx6_r, 1100LL, pool);
AddTx(tx7_r, 9000LL, pool);
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4);
pool.TrimToSize(GetVirtualTransactionSize(tx1));
pool.TrimToSize(GetVirtualTransactionSize(cTx));

This comment has been minimized.

Copy link
@MarcoFalke

MarcoFalke Dec 10, 2018

Member

Couldn't this just use tx1_r?

@practicalswift

This comment has been minimized.

Copy link
Member

commented Dec 10, 2018

Concept ACK

Explicit is better than implicit – especially when it comes to conversions.

@lucash-dev lucash-dev force-pushed the lucash-dev:explicit-CMutableTransaction-conversion-test branch to 8db0c3d Dec 12, 2018

@jb55

This comment has been minimized.

Copy link
Contributor

commented Dec 12, 2018

explicit utACK 8db0c3d

@MarcoFalke MarcoFalke merged commit 8db0c3d into bitcoin:master Dec 12, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

MarcoFalke added a commit that referenced this pull request Dec 12, 2018

Merge #14908: test: Removed implicit CTransaction constructor calls f…
…rom tests and benchmarks.

8db0c3d Removed implicit CTransaction conversion from benchmaks (lucash-dev)
ed61abe Removed implicit CTransaction constructor from tests (lucash-dev)

Pull request description:

  This PR was split from #14906 and is a prerequisite for it.
  It updates tests and benchmarks, removing all implicit calls to `CTransaction(CMutableTransaction&)` constructors. This will make possible making the constructor explicit in the next PR.
  The original rationale for making the constructor explicit:

   - Conversion constructors should not be explicit unless there's a strong reason for it (in the opinion of, for example, https://google.github.io/styleguide/cppguide.html, and https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ro-conversion. Let me know your take on this).
   - This particular conversion is very costly -- it implies a serialization plus hash of the transaction.
   - Even though `CTransaction` and `CMutableTransaction` represent the same data, they have very different use cases and performance properties.
   - Making it explicit allows for easier reasoning of performance trade-offs.
   - There has been previous performance issues caused by unneeded use of this implicit conversion.
   - This PR creates a map for places to look for possible refactoring and performance gains (this benefit still holds if the PR is not merged).

Tree-SHA512: de8073aa6ff8a3153bcbe10818616677ecf9598e4978d8a0b4c39a262e71c36be5679cec08554c760d1f011ba6d37350318248eef15f6d9b86f9e4462b2de0d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.