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.
This commit is contained in:
JoelKatz
2015-03-25 13:03:10 -07:00
committed by Tom Ritchford
parent 4868135d47
commit 47c6ab0ced
4 changed files with 6 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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<Ledger> (true, std::ref (*firstLedger));

View File

@@ -274,6 +274,7 @@ void
SHAMap::setImmutable ()
{
assert (state_ != SHAMapState::Invalid);
unshare ();
state_ = SHAMapState::Immutable;
}

View File

@@ -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 ();