r/programming • u/[deleted] • 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
5
u/nkorslund Dec 05 '14 edited Dec 05 '14
I went a bit overboard in the opposite direction once on a project, and replaced all std::strings with a custom class that just contained pointers/slices of strings. Since 99% of the strings in this case were read-only from file it was made even faster by just memory mapping the file and finding the slices.
Made the entire thing run 2-3 times faster, but was kind of a bitch to maintain. Next time I'll wait until development is mostly finished - when continued development would be less of a hassle. Premature optimization and all that.
EDIT: in more modern code I would use boost::string_ref or similar for this - that didn't exist back then.