I was reading about multiplication being faster than division in C++: https://stackoverflow.com/a/17883577/
99% of the regular contributors in this repository know C++ better than me so I think this must have already been discussed or considered while doing calculations although I couldn't find anything in doc/developer-notes.md
Division is done at lot of places which could be replaced with multiplication. Are there any downsides?
Example: GetMinFee() in src/txmempool.cpp
CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const {
LOCK(cs);
if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
return CFeeRate(llround(rollingMinimumFeeRate));
int64_t time = GetTime();
if (time > lastRollingFeeUpdate + 10) {
double halflife = ROLLING_FEE_HALFLIFE;
- if (DynamicMemoryUsage() < sizelimit / 4)
+ if (DynamicMemoryUsage() < sizelimit * 0.25)
- halflife /= 4;
+ halflife *= 0.25;
- else if (DynamicMemoryUsage() < sizelimit / 2)
+ else if (DynamicMemoryUsage() < sizelimit * 0.5)
- halflife /= 2;
+ halflife *= 0.5;
rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
lastRollingFeeUpdate = time;
- if (rollingMinimumFeeRate < (double)incrementalRelayFee.GetFeePerK() / 2) {
+ if (rollingMinimumFeeRate < (double)incrementalRelayFee.GetFeePerK() * 0.5) {
rollingMinimumFeeRate = 0;
return CFeeRate(0);
}
}
return std::max(CFeeRate(llround(rollingMinimumFeeRate)), incrementalRelayFee);
}