
At 9:41 AM -0700 7/26/05, Robert Ramey wrote:
Thinking about this, its very odd to me that just initializing some STL containers takes up so much time.
It does seem odd, so I've spent some more time looking at this. If I haven't messed up somewhere, it looks like the empty container initializations might only be accounting for about 10% of the total constructor time. But there is another container which is being affected by the reset trick which might not be empty: the m_helpers member of boost::archive::detail::basic_archive_impl. I'm not clearing that std::set (it seemed like something that shouldn't be cleared in order to reuse the archive, though I haven't fully figured out how it is used). I haven't yet figured out a way to measure it's impact in isolation (maybe I'll have to try making lots of archives with and without some part of its implementation commented out, which probably involves a rebuild of boost, so probably not today). So I'm not certain exactly why the reset and reuse approach helps as much as it does, just that it does. By the way, the times here are not individually large; archive constructor time on the 2GHz Pentium I'm using for these tests is 6-8 usec. But it adds up when one is doing *lots* of them, especially if they aren't actually necessary. Also, some of the intended target platforms for what I'm working on aren't nearly as fast as this test machine.