El 10/02/2014 9:18, Adam Romanek escribió:
Hi!
Recently I've been trying to improve the performance of a code that makes heavy use of std::string (lots of constructions and destructions). My first thought was to use boost::container::string as it does not use reference-counting and uses small-string optimization, so it should be a perfect replacement for std::string when it comes to performance.
Right... But the problem is that switching to boost::container::string only made things worse in the general case. I wrote "in the general case" because when strings to be held are small and SSO may be applied then boost::container::string outperforms std::string considerably. However, in the general case constructing boost::container::string from a C string is significantly slower than constructing std::string.
My investigation showed that std::string uses memcpy to copy the C string into its buffer while boost::container::string does not. The memcpy comes from std::char_traits::copy so maybe boost::container::string could use it too? I guess the rest of operations from std::char_traits (find, move, assign etc.) could be utilized too as std::char_traits has been carefully crafted with performance in mind.
Should I create a ticket for this issue?
Yes, please. I'm slowly trying to benchmark and improve Boost.Container performance, I haven't started optimizing basic_string so your ticket could be a good start point. In a quick inspection I see that the constructor is dispatched to basic_string::assign(It, It) and that assignment is not optimized at all. I should definitely write a assignment function that dispatches to std::char_traits::copy, as it could be used to optimize several member functions. Best, Ion