4 ms·
Uhh... you do realize C++ std::string has small string optimizations right? That would probably take care of most of the 30%. const string& would probably tak
by CyberDildonics 12y ago
Uhh... you do realize C++ std::string has small string optimizations right? That would probably take care of most of the 30%. const string& would probably take care of the rest. No program should have performance problems due to strings.
- Rusky 12y agoSmall string optimization doesn't help that much. Chrome's use of std::string accounts for almost half of all allocation: https://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ https://groups.google.com/a/chromium.org/forum/#!msg/chromiu...
- shawn-butler 12y agoAs always it would depend on the context of usage whether the allocations would be problematic. Use of SGI STL::rope<T, Alloc>[0] has helped me in the past in a similar scenario. It is part of SGI stl implementation that did not make it into part of the standard library specification although it should have, imho. Essentially ropes are character strings represented as a tree of concatenation nodes optimized for immuatability. A rope may contain shared subtrees so is really a directed acyclic graph where the out-edges of each vertex are ordered. Kind of search trees that are indexed by position. [0]: https://www.sgi.com/tech/stl/Rope.html https://www.sgi.com/tech/stl/Rope.html [1]: [pdf] http://www.cs.rit.edu/usr/local/pub/jeh/courses/QUARTERS/FP/Labs/CedarRope/rope-paper.pdf http://www.cs.rit.edu/usr/local/pub/jeh/courses/QUARTERS/FP/...
- CyberDildonics 12y agoThat doesn't mean that allocations are a big part of chrome's performance, and in fact I would guess that they aren't since allocations are a large performance win and chrome is optimized. Also, chrome being a web browser means a huge part of the program is strings.
- MichaelGG 12y agoMost of the code is C, and uses APR, but with its own wrappers. E.g. "project_sprintf" and such. Some of the strings aren't quite small enough, too. They're like HTTP header strings, unseparated. I agree no one should have this problem, but if you naïvely start passing char* around and have a complicated ownership model (that's probably technically unsound, but works in practice most of the time), you can end up duplicating and getting hurt.
- CyberDildonics 12y agostd::string's small string optimization is automatic, you don't have to do anything with it or about it. Bigger strings create allocations, small ones don't, and statistically most strings are small. Also if you use const references you can be sure that you aren't modifying the strings and aren't copying them. With C++11 you can move strings and so the ownership is explicit.
- hueving 12y agoUnless the entire program is based on manipulating and parsing large strings....
- CyberDildonics 12y agoBut then you could reference parts of large strings, copy small sections and manipulate those, etc. Modern programs can do 10 million heap allocations per second. If heap allocations are really a problem, that is a gigantic design flaw, and if it is happening with strings, simply using std::string should make a large impact. Surely not every string passed is both huge and needs to be copied.
- oldmanjay 12y agoit's amazingly easy to dismiss problems you don't fully understand and will never have to fix, but it's not a terribly interesting line of conversation to read. kinda feels like you masturbating all over a public forum.
- deleted 12y ago[deleted]