I have been using cereal in highly time-sensitive software where every microsecond counts. My program runs in a loop and serializes a struct
on every iteration. The struct
contains some STL containers and strings and thus the size can vary between iterations.
I noticed that cereal takes much longer to complete on the very first serialization, and much less time in subsequent serialization attempts. It took approximately 600 microseconds the first time, then averaged 80 microseconds subsequently.
After tracing through the library I haven't been able to determine what is different about the first attempt versus all others. I'm guessing it has to do with parsing my struct
or with allocating memory for the stringstream
.
I found this post interesting, in particular the recommendation to extend a cereal class to not use streams. I tried to create a version of the BinaryOutputArchive
class that used a void*
buffer instead of a std::ostream
, but have been unsuccessful getting things to compile. I also tried playing with the rdbuf
of the stringstream
as suggested here but I could not get it to serialize properly.
Does anyone have a recommendation on how to improve cereal's performance, especially on the very first serialization? Or perhaps a way to achieve deterministic latencies? Am I on the right track with my attempts above?