Opened 9 years ago

Last modified 9 years ago

#9116 new Bugs

Binary serialization: bitwise copying should also apply to single POD objects (it now only seems to work on arrays/collections)

Reported by: Louis Zanella <louis.zanella@…> Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.53.0 Severity: Optimization
Keywords: serialization, binary, bitwise, POD Cc:

Description

I'm trying to find the best settings for fast binary serialization of big POD objects. My tests indicate that, for a structure tagged as bitwise serializable, I only get better performance on arrays and vectors, not on individual objects.

For instance, say I have a structure made up 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, serializing a single BigStruct object takes considerably (at least 5 times) longer than serializing an array of 1 BigStruct object.

Attachments (2)

BigStruct.h (26.0 KB ) - added by Louis Zanella <louis.zanella@…> 9 years ago.
POD structure whose objects should be bitwise serializable
main.cpp (3.1 KB ) - added by Louis Zanella <louis.zanella@…> 9 years ago.
Program to demonstrate the flaw

Download all attachments as: .zip

Change History (3)

by Louis Zanella <louis.zanella@…>, 9 years ago

Attachment: BigStruct.h added

POD structure whose objects should be bitwise serializable

by Louis Zanella <louis.zanella@…>, 9 years ago

Attachment: main.cpp added

Program to demonstrate the flaw

comment:1 by Robert Ramey, 9 years ago

basically I like this. But ... what happens to old archives when we change this? Example

plane old data struct A { float a; double b; ... };

if we serialize this as a block - it'll be faster even though it serializes any empty space due to structure padding. But this will look different than serializing item by item, so this will break compatibility with old archives. This would imply reving the archive format, which I might be willing to do - but that takes more time and risk so I might want to think about it some more.

Robert Ramey

Note: See TracTickets for help on using tickets.