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

fees: optimize decay #11194

Closed
wants to merge 1 commit into from
Closed

Conversation

theuni
Copy link
Member

@theuni theuni commented Aug 29, 2017

As discussed briefly last week with @morcos and @sdaftuar.
Rather than jumping around, visit elements in-order. This produces a noticeable speedup.

I added the assertions because it's not entirely clear from the existing code if the bucket size is allowed to differ from the individual sizes. I can't imagine that that could be the case, so I'll remove them if preferred.

Additionally, I assume we could skip UpdateMovingAverages() altogether if no entries have ever been added, but it's not obvious to me how to do that without breaking something.

Rather than jumping around, visit elements in-order. This produces a noticeable
speedup.
@gmaxwell
Copy link
Contributor

Additionally, I assume we could skip UpdateMovingAverages() altogether if no entries have ever been added, but it's not obvious to me how to do that without breaking something.

An optimization like this would be important for IBD.

@theuni
Copy link
Member Author

theuni commented Aug 29, 2017

@gmaxwell Indeed. When profiling IBD for the first few hundred thousand blocks, some of my results showed this function alone accounting for ~5-10% of all cpu time spent on the message handling thread.

This change reduces those percentages to roughly half iirc, but obviously avoiding it entirely when possible would be best.

@promag
Copy link
Member

promag commented Aug 30, 2017

Additionally, I assume we could skip UpdateMovingAverages() altogether if no entries have ever been added, but it's not obvious to me how to do that without breaking something.

How about not Record() it if current tip is too old? In other words, just Record() and UpdateMovingAverages() when approaching live tip?

Edit: when in IBD.

@gmaxwell
Copy link
Contributor

FWIW, I benchmarked a sync completely bypassing CBlockPolicyEstimator::processBlock and it was effectively the same speed (0.5% faster, but that could well be noise).

@promag
Copy link
Member

promag commented Aug 31, 2017

You mean speed in IBD, not CPU usage right?

@gmaxwell
Copy link
Contributor

gmaxwell commented Aug 31, 2017

Yes, though on this host (and in this benchmark) IBD is more or less cpu limited. I didn't intend to suggest that we shouldn't optimize here, but it's apparently not a huge it in IBD as cfields was initially concerned about it being.

}
assert(txCtAvg.size() == buckets.size());
for (auto& bucket : txCtAvg) {
bucket *= decay;
Copy link

@Dllieu Dllieu Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it might be more clear to write the following

auto applyDecay = [&decay, &buckets](std::vector<double>& transactions)
{
    assert(transactions.size() == buckets.size());
    for (double& bucket : transactions)
    {
        bucket *= decay;
    }
};

for (auto& elem : confAvg)
{
    applyDecay(elem);
}

for (auto& elem : failAvg)
{
    applyDecay(elem);
}

applyDecay(avg);
applyDecay(txCtAvg);

Copy link
Contributor

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please lets not add more asserts in non-consensus/net code. Without the asserts happy with this or @Dllieu's suggestion.

@DrahtBot DrahtBot closed this Jul 20, 2018
@DrahtBot
Copy link
Contributor

The last travis run for this pull request was 324 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@DrahtBot DrahtBot reopened this Jul 20, 2018
@laanwj
Copy link
Member

laanwj commented Jan 9, 2019

Last activity on this was in 2017, going to close this and add "up for grabs". Let me know if you want me to reopen it.

@laanwj laanwj closed this Jan 9, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants