Increase binary serialization - why does bitwise copying work only on collections?

Using syntactic serialization, I am trying to find the best settings for fast binary serialization of large objects. My tests show that for a structure labeled with bitwise serializable, I get better performance on arrays (and vectors), and not on individual objects.

For example, let's say I have this structure consisting only of POD types

struct BigStruct { double m1; long long m2; float m3; // ... bool m499; short m500; }; namespace boost { namespace serialization { template <class Archive> void serialize(Archive& ioArchive, BigStruct& ioStruct, const unsigned int iVersion) { ioArchive & ioStruct.m1; ioArchive & ioStruct.m2; ioArchive & ioStruct.m3; // ... ioArchive & ioStruct.m499; ioArchive & ioStruct.m500; } } } #include <boost/serialization/is_bitwise_serializable.hpp> BOOST_IS_BITWISE_SERIALIZABLE(BigStruct); 

Then serialize one object

 { std::ofstream outStream(tmpFolder + "/BinarySerializationOfBigStruct.txt", std::ios_base::binary); boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header); BigStruct bigStruct; std::clock_t c_start = std::clock(); binOutArchive << bigStruct; std::clock_t c_end = std::clock(); // ...compute elapsed time... } 

takes about 7 times longer than serializing an array of 1 object

 { std::ofstream outStream(tmpFolder + "/BinarySerializationOfBigStructArray.txt", std::ios_base::binary); boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header); BigStruct bigStructArray[1]; std::clock_t c_start = std::clock(); binOutArchive << bigStructArray; std::clock_t c_end = std::clock(); // ...compute elapsed time... } 

Am I missing something? Is this an oversight in forcing serialization?

BTW I am using boost v1.53.

+4
source share

All Articles