6 ms·
folly::fbstring, a drop-in replacement for std::string, is part of the folly library that we (Facebook) open sourced a while back. It allocates small strings i
by ctur 12y ago
folly::fbstring, a drop-in replacement for std::string, is part of the folly library that we (Facebook) open sourced a while back. It allocates small strings in-line and larger strings on the heap and has optimizations for medium and large strings, too. It's proven quite effective for us, particularly when used with jemalloc, which it conspires with for more optimal memory management. We use it as std::string for our C++ applications and libraries, completely replacing std::string both for our own code and third-party code.
https://github.com/facebook/folly/blob/master/folly/docs/FBString.md https://github.com/facebook/folly/blob/master/folly/docs/FBS...
In addition, it is worth noting folly::StringPiece (from folly/Range.h), which is generally a better interface for working with in-memory ranges of bytes. Hardly a new idea (it's inspired by similar libraries, such as in re2), but it permeates the APIs of many of our larger C++ systems, and folly itself, and often avoids passing std::string objects around at all.
Finally, there is also folly::fbvector, which offers similar improvements over std::vector.
- raverbashing 12y agoYeah, and if I want to use it I need to replace std::string all around my code. I can't use it for other libraries, unless I replace and recompile them. And tomorrow a new library comes I need to replace everything again. Your effort is commendable, and I know squeezing gains are important in the case of fb, but in the end it's just locking yourself in a library that should've been a second though/built in.
- Cthulhu_ 12y ago1. Find / replace, I'm sure the API is simple enough and performance gains are worth the effort. 3. You don't need to replace anything, ever - only if you feel like your string performance is lacking, and that particular new library satisfies your needs (in terms of effort vs performance gains). I don't get why people believe that whenever something new comes out they have to switch over, and as a result are terrified of innovation. 4. I disagree with the "should've been built in" statement; the default std::string implementation is good enough for most (like any std:: thing). Besides, std:string was designed 25+ years ago, over a dozen CPU generations ago; the demands of today are must different.
- raverbashing 12y agoI agree with most points, but "std:string was designed 25+ years ago, over a dozen CPU generations ago; the demands of today are must different." Sure, but you don't need to break the API for that You can replace the allocator in a C program without changing malloc/free to something else, this might have been a design goal. This way you can go back and forth to it, run your tests again, compare performance again, etc
- orbitur 12y agoSo what are you saying exactly? Stick with std::string until the the stdlib devs make it better? I don't think find/replace and including this library until something better comes along is an insurmountable problem.
- im2w1l 12y agoIf only they all implemented something like java.lang.CharSequence... "A CharSequence is a readable sequence of char values. This interface provides uniform, read-only access to many different kinds of char sequences. "
- nostrademons 12y agoNot necessarily - you can find the system headers on your machine and then do 'cp folly/FBString.h /usr/include/c++/4.9.1/string', and then every time you do #include <string> it will pick up Folly's FBString. If a new version comes out, just drop it there. If you're a large corporation, just modify your build system to use your custom standard headers. It sounds like this is what Facebook does - no Facebook code actually references FBString, it just uses std::string and Facebook's implementation of std::string is the Folly version. Google does something similar, where they replaced std::string with their own more efficient version, and everybody just uses it like a normal string.
- riffraff 12y agoFWIW, the email thread does say that some "base::StringPiece" should be used more often.
- thrownaway2424 12y agoStringPiece is here https://chromium.googlesource.com/chromium/src/base/+/master/strings/string_piece.h https://chromium.googlesource.com/chromium/src/base/+/master...
- thrownaway2424 12y agoIt hardly seems like introducing yet another type can solve this problem which is caused by temporary conversion back and forth between string and char*.
- pja 12y agoDoes folly "just build" on current Ubuntu / Debian boxes now? When it first came out I had enormously trouble getting it to build at all.