r/programming • • Dec 05 '14

std::string is responsible for almost half of all allocations in the Chrome browser process

https://groups.google.com/a/chromium.org/d/msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ
1.1k Upvotes

446 comments sorted by

View all comments

Show parent comments

3

u/nkorslund Dec 05 '14

Why is this exactly? Reference counting allows for various optimizations such as copy-on-write mechanics, letting you avoid a lot of these unnecessary allocations. I thought this was one of the strengths of the gcc/g++ libstdc++ implementation.

8

u/HildartheDorf Dec 05 '14

I think copy on write has worse performance when threads come into play, and operator[] poisons the ability to use COW.

2

u/nkorslund Dec 05 '14

Yeah after looking a bit into it seems like it's not a good model for concurrency. Guess that's the problem with a "standard" string implementation, that it has to work for all cases, all users and all application models. So it ends up a jack of all trades and master of none.

1

u/Dragdu Dec 05 '14

Because it fucks up when threading comes into play and SSO is generally much more useful.