Accept ledgers more efficiently by avoiding allocate/allocate/copy/copy/free cycles.

This commit is contained in:
JoelKatz
2013-05-14 11:49:33 -07:00
parent baf2841873
commit 6a84a95979
4 changed files with 23 additions and 22 deletions

View File

@@ -49,12 +49,11 @@ void ALTransaction::buildJson()
if (!mAffected.empty())
{
Json::Value affected(Json::arrayValue);
Json::Value& affected = (mJson["affected"] = Json::arrayValue);
BOOST_FOREACH(const RippleAddress& ra, mAffected)
{
affected.append(ra.humanAccountID());
}
mJson["affected"] = affected;
}
}
@@ -64,7 +63,7 @@ AcceptedLedger::AcceptedLedger(Ledger::ref ledger) : mLedger(ledger)
for (SHAMapItem::pointer item = txSet.peekFirstItem(); !!item; item = txSet.peekNextItem(item->getTag()))
{
SerializerIterator sit(item->peekSerializer());
insert(ALTransaction(ledger->getLedgerSeq(), sit));
insert(boost::make_shared<ALTransaction>(ledger->getLedgerSeq(), sit));
}
}
@@ -78,16 +77,16 @@ AcceptedLedger::pointer AcceptedLedger::makeAcceptedLedger(Ledger::ref ledger)
return ret;
}
void AcceptedLedger::insert(const ALTransaction& at)
void AcceptedLedger::insert(ALTransaction::ref at)
{
assert(mMap.find(at.getIndex()) == mMap.end());
mMap.insert(std::make_pair(at.getIndex(), at));
assert(mMap.find(at->getIndex()) == mMap.end());
mMap.insert(std::make_pair(at->getIndex(), at));
}
const ALTransaction* AcceptedLedger::getTxn(int i) const
ALTransaction::pointer AcceptedLedger::getTxn(int i) const
{
map_t::const_iterator it = mMap.find(i);
if (it == mMap.end())
return NULL;
return &it->second;
return ALTransaction::pointer();
return it->second;
}

View File

@@ -19,6 +19,8 @@ protected:
void buildJson();
public:
typedef boost::shared_ptr<ALTransaction> pointer;
typedef const pointer& ref;
ALTransaction(uint32 ledgerSeq, SerializerIterator& sit);
ALTransaction(SerializedTransaction::ref, TransactionMetaSet::ref);
@@ -44,7 +46,7 @@ class AcceptedLedger
public:
typedef boost::shared_ptr<AcceptedLedger> pointer;
typedef const pointer& ret;
typedef std::map<int, ALTransaction> map_t; // Must be an ordered map!
typedef std::map<int, ALTransaction::pointer> map_t; // Must be an ordered map!
typedef map_t::value_type value_type;
typedef map_t::const_iterator const_iterator;
@@ -52,7 +54,7 @@ protected:
Ledger::pointer mLedger;
map_t mMap;
void insert(const ALTransaction&);
void insert(ALTransaction::ref);
static TaggedCache<uint256, AcceptedLedger> ALCache;
AcceptedLedger(Ledger::ref ledger);
@@ -68,7 +70,7 @@ public:
int getLedgerSeq() const { return mLedger->getLedgerSeq(); }
int getTxnCount() const { return mMap.size(); }
const ALTransaction* getTxn(int) const;
ALTransaction::pointer getTxn(int) const;
};
#endif

View File

@@ -471,12 +471,12 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
BOOST_FOREACH(const AcceptedLedger::value_type& vt, aLedger->getMap())
{
uint256 txID = vt.second.getTransactionID();
uint256 txID = vt.second->getTransactionID();
theApp->getMasterTransaction().inLedger(txID, mLedgerSeq);
db->executeSQL(boost::str(deleteAcctTrans % txID.GetHex()));
const std::vector<RippleAddress>& accts = vt.second.getAffected();
const std::vector<RippleAddress>& accts = vt.second->getAffected();
if (!accts.empty())
{
std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq, TxnSeq) VALUES ";
@@ -496,7 +496,7 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
sql += "',";
sql += boost::lexical_cast<std::string>(getLedgerSeq());
sql += ",";
sql += boost::lexical_cast<std::string>(vt.second.getTxnSeq());
sql += boost::lexical_cast<std::string>(vt.second->getTxnSeq());
sql += ")";
}
sql += ";";
@@ -507,7 +507,7 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
cLog(lsWARNING) << "Transaction in ledger " << mLedgerSeq << " affects no accounts";
db->executeSQL(SerializedTransaction::getMetaSQLInsertReplaceHeader() +
vt.second.getTxn()->getMetaSQL(getLedgerSeq(), vt.second.getEscMeta()) + ";");
vt.second->getTxn()->getMetaSQL(getLedgerSeq(), vt.second->getEscMeta()) + ";");
}
db->executeSQL("COMMIT TRANSACTION;");
}

View File

@@ -1439,8 +1439,8 @@ void NetworkOPs::pubLedger(Ledger::ref accepted)
{
BOOST_FOREACH(const AcceptedLedger::value_type& vt, alpAccepted->getMap())
{
cLog(lsTRACE) << "pubAccepted: " << vt.second.getJson();
pubValidatedTransaction(lpAccepted, vt.second);
cLog(lsTRACE) << "pubAccepted: " << vt.second->getJson();
pubValidatedTransaction(lpAccepted, *vt.second);
}
}
}