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

Some more perf improvements #3204

Merged
merged 8 commits into from
Oct 13, 2021

Conversation

MonsieurNicolas
Copy link
Contributor

Description

This is a follow up PR from #3180 this time focusing on performance while replaying transactions.

On my laptop the changes yield a 25% speed improvement (real time), broken down as follows:

  • make commit/rollback noexcept. Historically LedgerTxn was written in an exception safe way, but we eventually added handlers to just crash in certain scenarios. There are no real benefits of allowing those functions to throw in other situations, as a result we can perform operations that are irreversible. See the next commit
  • perform changes "in place" when committing. ~12% speed improvement. This avoids copying data from child -> parent all the time.
  • cache "hash" within InternalLedgerKey. ~4% speed improvement. We could probably take this idea further, there are other places where we use LedgerKey as key (that could benefit from this change)
  • avoid looking up entries in mActive when calling updateEntry. 10% speed improvement. In most situations we already know if the key is active, so we can just call the right function.

@MonsieurNicolas
Copy link
Contributor Author

changed "multi order book" to not use AssetPair (which causes allocations), compared to what is described in the description, this gives --> 40% speedup for bucket apply, and 10% improvement when applying ledgers.

src/ledger/LedgerTxnImpl.h Show resolved Hide resolved
src/ledger/LedgerTxnImpl.h Show resolved Hide resolved
src/ledger/LedgerTxnImpl.h Show resolved Hide resolved
src/ledger/InternalLedgerEntry.h Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
mChild->forAllWorstBestOffers(
[&](Asset const& buying, Asset const& selling,
std::shared_ptr<OfferDescriptor const>& desc) {
updateWorstBestOffer(AssetPair{buying, selling}, desc);
Copy link
Contributor

Choose a reason for hiding this comment

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

I commented earlier about avoiding the copy. I think this one is less scary than the previous one, because OfferDescriptors should never leak out of LedgerTxn. But we should make sure we understand what safety is being sacrificed.

Copy link
Contributor Author

@MonsieurNicolas MonsieurNicolas left a comment

Choose a reason for hiding this comment

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

@jonjove I think I addressed your comments

src/ledger/LedgerTxnImpl.h Show resolved Hide resolved
src/ledger/LedgerTxnImpl.h Show resolved Hide resolved
src/ledger/LedgerTxnImpl.h Show resolved Hide resolved
src/ledger/InternalLedgerEntry.h Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerTxn.cpp Outdated Show resolved Hide resolved
@jonjove
Copy link
Contributor

jonjove commented Oct 13, 2021

Looks good to me, please squash when you get a chance. @sisuresh I remember you had planned to review this as well, have you done so?

@jonjove
Copy link
Contributor

jonjove commented Oct 13, 2021

r+ 6ac102f

@latobarita latobarita merged commit fcd3c71 into stellar:master Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants