diff options
author | Marc Laukien <marc@zeroc.com> | 2005-02-24 17:34:55 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2005-02-24 17:34:55 +0000 |
commit | e4843a84aee34f87b6ddff1f60f3901fa5d8eed1 (patch) | |
tree | 4ee5698a05625634f56085806c1cb59b4960ed13 /cpp | |
parent | Added missing break statement (diff) | |
download | ice-e4843a84aee34f87b6ddff1f60f3901fa5d8eed1.tar.bz2 ice-e4843a84aee34f87b6ddff1f60f3901fa5d8eed1.tar.xz ice-e4843a84aee34f87b6ddff1f60f3901fa5d8eed1.zip |
various performance improvements
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/demo/Ice/throughput/Client.cpp | 6 | ||||
-rw-r--r-- | cpp/include/Ice/Buffer.h | 109 | ||||
-rw-r--r-- | cpp/src/Freeze/ObjectStore.cpp | 10 | ||||
-rw-r--r-- | cpp/src/Ice/.depend | 1 | ||||
-rw-r--r-- | cpp/src/Ice/Buffer.cpp | 118 | ||||
-rw-r--r-- | cpp/src/Ice/Makefile | 1 | ||||
-rw-r--r-- | cpp/src/Ice/StreamI.cpp | 5 | ||||
-rw-r--r-- | cpp/src/Ice/ice.dsp | 4 | ||||
-rw-r--r-- | cpp/src/slice2freeze/Main.cpp | 9 |
9 files changed, 183 insertions, 80 deletions
diff --git a/cpp/demo/Ice/throughput/Client.cpp b/cpp/demo/Ice/throughput/Client.cpp index 97d03b5f771..cdb0717e4d8 100644 --- a/cpp/demo/Ice/throughput/Client.cpp +++ b/cpp/demo/Ice/throughput/Client.cpp @@ -19,9 +19,9 @@ menu() cout << "usage:\n" "toggle type of data to send\n" - " 1: byte sequence (default)\n" - " 2: string { \"hello\" } sequence\n" - " 3: struct { \"hello\", \"3.14\" } sequence\n" + " 1: sequence of bytes (default)\n" + " 2: sequence of strings (\"hello\")\n" + " 3: sequence of structs with a string (\"hello\") and a double\n" "select test to run\n" " t: send sequence as twoway\n" " o: send sequence as oneway\n" diff --git a/cpp/include/Ice/Buffer.h b/cpp/include/Ice/Buffer.h index 3400b5f6cb9..0879b1cc5d0 100644 --- a/cpp/include/Ice/Buffer.h +++ b/cpp/include/Ice/Buffer.h @@ -12,6 +12,8 @@ #include <Ice/Config.h> +//#define ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + namespace IceInternal { @@ -22,13 +24,9 @@ public: Buffer() : i(b.begin()) { } virtual ~Buffer() { } - void swap(Buffer& other) - { - b.swap(other.b); - std::swap(i, other.i); - } + void swap(Buffer&); - class Container : public IceUtil::noncopyable + class ICE_API Container : public IceUtil::noncopyable { public: @@ -45,16 +43,32 @@ public: typedef int difference_type; typedef size_t size_type; +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + Container() : + _buf(_fixed), + _size(0), + _capacity(_fixedSize) + { + } +#else Container() : _buf(0), _size(0), _capacity(0) { } +#endif ~Container() { +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + if(_buf != _fixed) + { + free(_buf); + } +#else free(_buf); +#endif } iterator begin() @@ -87,47 +101,27 @@ public: return !_size; } - void swap(Container& other) - { - std::swap(_buf, other._buf); - std::swap(_size, other._size); - std::swap(_capacity, other._capacity); - } + void swap(Container&); void clear() { +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + if(_buf != _fixed) + { + free(_buf); + _buf = _fixed; + } + _size = 0; + _capacity = _fixedSize; +#else free(_buf); _buf = 0; _size = 0; _capacity = 0; +#endif } - void resize(size_type n) - { - if(n == 0) - { - clear(); - } - else - { - _size = n; - - if(_size > _capacity) - { - _capacity = std::max<size_type>(_size, 2 * _capacity); - _capacity = std::max<size_type>(static_cast<size_type>(240), _capacity); - - if(_buf) - { - _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); - } - else - { - _buf = reinterpret_cast<pointer>(malloc(_capacity)); - } - } - } - } + void resize(size_type); void push_back(value_type v) { @@ -147,35 +141,6 @@ public: return _buf[n]; } - // - // Special operations. - // - - void copyFromVector(const std::vector<value_type>& v) - { - if(v.empty()) - { - clear(); - } - else - { - resize(v.size()); - memcpy(_buf, &v[0], v.size()); - } - } - - void copyToVector(std::vector<value_type>& v) - { - if(empty()) - { - v.clear(); - } - else - { - std::vector<value_type>(_buf, _buf + _size).swap(v); - } - } - private: Container(const Container&); @@ -184,6 +149,16 @@ public: pointer _buf; size_type _size; size_type _capacity; + +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + // + // For small buffers, we stack-allocate the memory. Only when + // a buffer size larger than _fixedSize is requested, we + // allocate memory dynamically. + // + static const size_type _fixedSize = 64; + value_type _fixed[_fixedSize]; +#endif }; Container b; diff --git a/cpp/src/Freeze/ObjectStore.cpp b/cpp/src/Freeze/ObjectStore.cpp index dfbe0de1651..a8cc39c9079 100644 --- a/cpp/src/Freeze/ObjectStore.cpp +++ b/cpp/src/Freeze/ObjectStore.cpp @@ -257,7 +257,7 @@ Freeze::ObjectStore::marshal(const Identity& ident, Key& bytes, const Communicat IceInternal::InstancePtr instance = IceInternal::getInstance(communicator); IceInternal::BasicStream stream(instance.get()); ident.__write(&stream); - stream.b.copyToVector(bytes); + vector<Byte>(stream.b.begin(), stream.b.end()).swap(bytes); } void @@ -265,7 +265,8 @@ Freeze::ObjectStore::unmarshal(Identity& ident, const Key& bytes, const Communic { IceInternal::InstancePtr instance = IceInternal::getInstance(communicator); IceInternal::BasicStream stream(instance.get()); - stream.b.copyFromVector(bytes); + stream.b.resize(bytes.size()); + memcpy(&stream.b[0], &bytes[0], bytes.size()); stream.i = stream.b.begin(); ident.__read(&stream); } @@ -279,7 +280,7 @@ Freeze::ObjectStore::marshal(const ObjectRecord& v, Value& bytes, const Communic v.__write(&stream); stream.writePendingObjects(); stream.endWriteEncaps(); - stream.b.copyToVector(bytes); + vector<Byte>(stream.b.begin(), stream.b.end()).swap(bytes); } void @@ -288,7 +289,8 @@ Freeze::ObjectStore::unmarshal(ObjectRecord& v, const Value& bytes, const Commun IceInternal::InstancePtr instance = IceInternal::getInstance(communicator); IceInternal::BasicStream stream(instance.get()); stream.sliceObjects(false); - stream.b.copyFromVector(bytes); + stream.b.resize(bytes.size()); + memcpy(&stream.b[0], &bytes[0], bytes.size()); stream.i = stream.b.begin(); stream.startReadEncaps(); v.__read(&stream); diff --git a/cpp/src/Ice/.depend b/cpp/src/Ice/.depend index 3d397320e44..629b20efe59 100644 --- a/cpp/src/Ice/.depend +++ b/cpp/src/Ice/.depend @@ -1,5 +1,6 @@ Acceptor.o: Acceptor.cpp ../Ice/Acceptor.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../Ice/AcceptorF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h ../Ice/TransceiverF.h Application.o: Application.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/FacetMap.h ../../include/Ice/ServantLocator.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/IceUtil/GCRecMutex.h ../../include/IceUtil/RecMutex.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Incoming.h ../../include/Ice/ServantManagerF.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Process.h ../../include/Ice/Outgoing.h ../../include/Ice/Direct.h ../../include/Ice/Connection.h ../../include/Ice/Functional.h ../../include/IceUtil/Functional.h ../../include/Ice/Stream.h ../../include/IceUtil/StaticMutex.h ../../include/IceUtil/CtrlCHandler.h ../../include/IceUtil/GC.h ../../include/IceUtil/Thread.h +Buffer.o: Buffer.cpp ../../include/Ice/Buffer.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h BasicStream.o: BasicStream.cpp ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/Buffer.h ../Ice/Instance.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/RecMutex.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../../include/Ice/LoggerF.h ../../include/Ice/StatsF.h ../Ice/TraceLevelsF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/IceUtil/GCRecMutex.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/Proxy.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../Ice/ProxyFactory.h ../../include/Ice/ObjectFactory.h ../Ice/ObjectFactoryManager.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/LocalException.h ../../include/Ice/BuiltinSequences.h ../Ice/Protocol.h ../../include/Ice/FactoryTable.h ../../include/Ice/FactoryTableDef.h ../../include/IceUtil/StaticMutex.h ../../include/Ice/UserExceptionFactoryF.h ../Ice/TraceUtil.h ../Ice/TraceLevels.h ../../include/Ice/LoggerUtil.h BuiltinSequences.o: BuiltinSequences.cpp ../../include/Ice/BuiltinSequences.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/IceUtil/GCRecMutex.h ../../include/IceUtil/RecMutex.h ../../include/Ice/IncomingAsyncF.h CommunicatorF.o: CommunicatorF.cpp ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h diff --git a/cpp/src/Ice/Buffer.cpp b/cpp/src/Ice/Buffer.cpp new file mode 100644 index 00000000000..02d8295ffba --- /dev/null +++ b/cpp/src/Ice/Buffer.cpp @@ -0,0 +1,118 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Buffer.h> +#include <Ice/LocalException.h> + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +void +IceInternal::Buffer::swap(Buffer& other) +{ +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + Container::difference_type pos = i - b.begin(); + Container::difference_type otherPos = other.i - other.b.begin(); + b.swap(other.b); + i = b.begin() + otherPos; + other.i = other.b.begin() + pos; +#else + b.swap(other.b); + std::swap(i, other.i); +#endif +} + +void +IceInternal::Buffer::Container::swap(Container& other) +{ +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + if(_buf == _fixed) + { + if(other._buf == other._fixed) + { + value_type tmp[_fixedSize]; + memcpy(tmp, _fixed, _size); + memcpy(_fixed, other._fixed, other._size); + memcpy(other._fixed, tmp, _size); + } + else + { + _buf = other._buf; + memcpy(other._fixed, _fixed, _size); + other._buf = other._fixed; + } + } + else + { + if(other._buf == other._fixed) + { + other._buf = _buf; + memcpy(_fixed, other._fixed, other._size); + _buf = _fixed; + } + else + { + std::swap(_buf, other._buf); + } + } +#else + std::swap(_buf, other._buf); +#endif + + std::swap(_size, other._size); + std::swap(_capacity, other._capacity); +} + +void +IceInternal::Buffer::Container::resize(size_type n) +{ + if(n == 0) + { + clear(); + } + else + { + if(n > _capacity) + { + _capacity = std::max<size_type>(n, 2 * _capacity); + _capacity = std::max<size_type>(static_cast<size_type>(240), _capacity); + +#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION + if(_buf != _fixed) + { + _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); + } + else + { + _buf = reinterpret_cast<pointer>(malloc(_capacity)); + memcpy(_buf, _fixed, _size); + } +#else + if(_buf) + { + _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); + } + else + { + _buf = reinterpret_cast<pointer>(malloc(_capacity)); + } +#endif + + if(!_buf) + { + SyscallException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + } + + _size = n; + } +} diff --git a/cpp/src/Ice/Makefile b/cpp/src/Ice/Makefile index d98809d43fb..09991eb6ea2 100644 --- a/cpp/src/Ice/Makefile +++ b/cpp/src/Ice/Makefile @@ -17,6 +17,7 @@ TARGETS = $(call mklibtargets,$(libdir)/$(LIBFILENAME),$(libdir)/$(SONAME),$(li OBJS = Acceptor.o \ Application.o \ + Buffer.o \ BasicStream.o \ BuiltinSequences.o \ CommunicatorF.o \ diff --git a/cpp/src/Ice/StreamI.cpp b/cpp/src/Ice/StreamI.cpp index 5dda15a3b30..b11789d619a 100644 --- a/cpp/src/Ice/StreamI.cpp +++ b/cpp/src/Ice/StreamI.cpp @@ -35,7 +35,8 @@ IceInternal::BasicOutputStream::BasicOutputStream(IceInternal::Instance* instanc Ice::InputStreamI::InputStreamI(const Ice::CommunicatorPtr& communicator, const vector<Byte>& data) : _communicator(communicator), _is(IceInternal::getInstance(communicator).get(), this) { - _is.b.copyFromVector(data); + _is.b.resize(data.size()); + memcpy(&_is.b[0], &data[0], data.size()); _is.i = _is.b.begin(); } @@ -441,7 +442,7 @@ Ice::OutputStreamI::writePendingObjects() void Ice::OutputStreamI::finished(vector<Byte>& bytes) { - _os.b.copyToVector(bytes); + vector<Byte>(_os.b.begin(), _os.b.end()).swap(bytes); } // diff --git a/cpp/src/Ice/ice.dsp b/cpp/src/Ice/ice.dsp index 051d198ca4b..d09edc6e667 100644 --- a/cpp/src/Ice/ice.dsp +++ b/cpp/src/Ice/ice.dsp @@ -118,6 +118,10 @@ SOURCE=.\BasicStream.cpp # End Source File
# Begin Source File
+SOURCE=.\Buffer.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\BuiltinSequences.cpp
# End Source File
# Begin Source File
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index 46f94c52479..4c63ae376b7 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -169,7 +169,7 @@ writeCodecC(const TypePtr& type, const string& name, const string& freezeType, b { C << nl << "stream.endWriteEncaps();"; } - C << nl << "stream.b.copyToVector(bytes);"; + C << nl << "::std::vector<Ice::Byte>(stream.b.begin(), stream.b.end()).swap(bytes);"; C << eb; C << sp << nl << "void" << nl << name << "::read(" << typeToString(type) << "& v, " @@ -181,7 +181,8 @@ writeCodecC(const TypePtr& type, const string& name, const string& freezeType, b { C << nl << "stream.sliceObjects(false);"; } - C << nl << "stream.b.copyFromVector(bytes);"; + C << nl << "stream.b.resize(bytes.size());"; + C << nl << "::memcpy(&stream.b[0], &bytes[0], bytes.size());"; C << nl << "stream.i = stream.b.begin();"; if(encaps) { @@ -468,7 +469,7 @@ writeDictWithIndicesC(const string& name, const string& absolute, const Dict& di { C << nl << "__stream.writePendingObjects();"; } - C << nl << "__stream.b.copyToVector(__bytes);"; + C << nl << "::std::vector<Ice::Byte>(__stream.b.begin(), __stream.b.end()).swap(__bytes);"; } C << eb; } @@ -850,7 +851,7 @@ writeIndexC(const TypePtr& type, const TypePtr& memberType, const string& member { C << nl << "__stream.writePendingObjects();"; } - C << nl << "__stream.b.copyToVector(__bytes);"; + C << nl << "::std::vector<Ice::Byte>(__stream.b.begin(), __stream.b.end()).swap(__bytes);"; C << eb; } |