From 47c6ab0ced4563fe473c9396cbaea874619c2921 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 25 Mar 2015 13:03:10 -0700 Subject: [PATCH] Reduce SHAMapTreeNode copying during SHAMap unsharing: In some code paths, we bump the SHAMap sequence number before we unshare. This forces SHAMapTreeNode to be copied. By making the ledger immutable we cause the unsharing to occur earlier, eliminating the copies. --- src/ripple/app/ledger/LedgerMaster.cpp | 5 +++-- src/ripple/app/main/Application.cpp | 1 + src/ripple/shamap/SHAMap.h | 1 + src/ripple/shamap/impl/SHAMap.cpp | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ripple/app/ledger/LedgerMaster.cpp b/src/ripple/app/ledger/LedgerMaster.cpp index ee7b95deef..4a8b07fea4 100644 --- a/src/ripple/app/ledger/LedgerMaster.cpp +++ b/src/ripple/app/ledger/LedgerMaster.cpp @@ -394,8 +394,9 @@ public: } if (didApply) { - mCurrentLedger.set (ledger); - getApp().getOPs ().pubProposedTransaction (ledger, txn, result); + ledger->setImmutable (); // So the next line doesn't have to copy + mCurrentLedger.set (ledger); + getApp().getOPs ().pubProposedTransaction (ledger, txn, result); } return result; } diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 3e70418eb9..6cff83eac2 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -1084,6 +1084,7 @@ void ApplicationImp::startNewLedger () firstLedger->updateHash (); firstLedger->setClosed (); firstLedger->setAccepted (); + firstLedger->setImmutable(); m_ledgerMaster->pushLedger (firstLedger); Ledger::pointer secondLedger = std::make_shared (true, std::ref (*firstLedger)); diff --git a/src/ripple/shamap/SHAMap.h b/src/ripple/shamap/SHAMap.h index c97cb18feb..2fac043b85 100644 --- a/src/ripple/shamap/SHAMap.h +++ b/src/ripple/shamap/SHAMap.h @@ -274,6 +274,7 @@ void SHAMap::setImmutable () { assert (state_ != SHAMapState::Invalid); + unshare (); state_ = SHAMapState::Immutable; } diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index e043e56622..962ae1207d 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -75,7 +75,7 @@ SHAMap::snapShot (bool isMutable) const newMap.seq_ = seq_ + 1; newMap.root_ = root_; - if ((state_ != SHAMapState::Immutable) || !isMutable) + if ((state_ != SHAMapState::Immutable) || isMutable) { // If either map may change, they cannot share nodes newMap.unshare ();