Author: astitcher
Date: Mon Mar 5 19:12:43 2012
New Revision: 1297184
URL: http://svn.apache.org/viewvc?rev=1297184&view=rev
Log:
QPID-3883: Using application headers in messages causes a very large slowdown
Cache the size of a field table to prevent recomputation
Modified:
qpid/trunk/qpid/cpp/include/qpid/framing/FieldTable.h
qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp
Modified: qpid/trunk/qpid/cpp/include/qpid/framing/FieldTable.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/framing/FieldTable.h?rev=1297184&r1=1297183&r2=1297184&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/framing/FieldTable.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/framing/FieldTable.h Mon Mar 5 19:12:43
2012
@@ -56,7 +56,7 @@ class FieldTable
typedef ValueMap::reference reference;
typedef ValueMap::value_type value_type;
- QPID_COMMON_INLINE_EXTERN FieldTable() {};
+ QPID_COMMON_EXTERN FieldTable();
QPID_COMMON_EXTERN FieldTable(const FieldTable& ft);
QPID_COMMON_EXTERN ~FieldTable();
QPID_COMMON_EXTERN FieldTable& operator=(const FieldTable& ft);
@@ -109,7 +109,7 @@ class FieldTable
QPID_COMMON_EXTERN std::pair <ValueMap::iterator, bool> insert(const
ValueMap::value_type&);
QPID_COMMON_EXTERN ValueMap::iterator insert(ValueMap::iterator, const
ValueMap::value_type&);
- void clear() { values.clear(); }
+ void clear();
// ### Hack Alert
@@ -117,6 +117,7 @@ class FieldTable
private:
ValueMap values;
+ mutable uint32_t cachedSize; // if = 0 then non cached size as 0 is not a
legal size
QPID_COMMON_EXTERN friend std::ostream& operator<<(std::ostream& out,
const FieldTable& body);
};
Modified: qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp?rev=1297184&r1=1297183&r2=1297184&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp Mon Mar 5 19:12:43 2012
@@ -31,6 +31,10 @@
namespace qpid {
namespace framing {
+FieldTable::FieldTable() : cachedSize(0)
+{
+}
+
FieldTable::FieldTable(const FieldTable& ft)
{
*this = ft;
@@ -40,17 +44,22 @@ FieldTable& FieldTable::operator=(const
{
clear();
values = ft.values;
+ cachedSize = ft.cachedSize;
return *this;
}
FieldTable::~FieldTable() {}
uint32_t FieldTable::encodedSize() const {
+ if (cachedSize != 0) {
+ return cachedSize;
+ }
uint32_t len(4/*size field*/ + 4/*count field*/);
for(ValueMap::const_iterator i = values.begin(); i != values.end(); ++i) {
// shortstr_len_byte + key size + value size
- len += 1 + (i->first).size() + (i->second)->encodedSize();
+ len += 1 + (i->first).size() + (i->second)->encodedSize();
}
+ cachedSize = len;
return len;
}
@@ -78,43 +87,53 @@ std::ostream& operator<<(std::ostream& o
void FieldTable::set(const std::string& name, const ValuePtr& value){
values[name] = value;
+ cachedSize = 0;
}
void FieldTable::setString(const std::string& name, const std::string& value){
values[name] = ValuePtr(new Str16Value(value));
+ cachedSize = 0;
}
void FieldTable::setInt(const std::string& name, const int value){
values[name] = ValuePtr(new IntegerValue(value));
+ cachedSize = 0;
}
void FieldTable::setInt64(const std::string& name, const int64_t value){
values[name] = ValuePtr(new Integer64Value(value));
+ cachedSize = 0;
}
void FieldTable::setTimestamp(const std::string& name, const uint64_t value){
values[name] = ValuePtr(new TimeValue(value));
+ cachedSize = 0;
}
void FieldTable::setUInt64(const std::string& name, const uint64_t value){
values[name] = ValuePtr(new Unsigned64Value(value));
+ cachedSize = 0;
}
void FieldTable::setTable(const std::string& name, const FieldTable& value)
{
values[name] = ValuePtr(new FieldTableValue(value));
+ cachedSize = 0;
}
void FieldTable::setArray(const std::string& name, const Array& value)
{
values[name] = ValuePtr(new ArrayValue(value));
+ cachedSize = 0;
}
void FieldTable::setFloat(const std::string& name, const float value){
values[name] = ValuePtr(new FloatValue(value));
+ cachedSize = 0;
}
void FieldTable::setDouble(const std::string& name, double value){
values[name] = ValuePtr(new DoubleValue(value));
+ cachedSize = 0;
}
FieldTable::ValuePtr FieldTable::get(const std::string& name) const
@@ -216,6 +235,7 @@ void FieldTable::decode(Buffer& buffer){
values[name] = ValuePtr(value);
}
}
+ cachedSize = 0;
}
bool FieldTable::operator==(const FieldTable& x) const {
@@ -230,17 +250,26 @@ bool FieldTable::operator==(const FieldT
void FieldTable::erase(const std::string& name)
{
- if (values.find(name) != values.end())
+ if (values.find(name) != values.end()) {
values.erase(name);
+ cachedSize = 0;
+ }
+}
+void FieldTable::clear()
+{
+ values.clear();
+ cachedSize = 0;
}
std::pair<FieldTable::ValueMap::iterator, bool> FieldTable::insert(const
ValueMap::value_type& value)
{
+ cachedSize = 0;
return values.insert(value);
}
FieldTable::ValueMap::iterator FieldTable::insert(ValueMap::iterator position,
const ValueMap::value_type& value)
{
+ cachedSize = 0;
return values.insert(position, value);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]