14 ms·
Folly - The Faceboook open source library
- luser001 14y agoI'm going to be taking a serious look at this for my own projects. I like Format: https://github.com/facebook/folly/blob/master/folly/docs/Format.md https://github.com/facebook/folly/blob/master/folly/docs/For... Histogram is going to come in handy. :) fbstring seems to be exactly what the doctor ordered. I like the emphasis on cooperating with the memory allocator in fbstring and fbvector. If the entire library does that, that's going to a big win for long-running programs: memory fragmentation can slowly increase program footprint, requiring the use of fancy arena allocators etc. I had fun reading their vector doc: https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md https://github.com/facebook/folly/blob/master/folly/docs/FBV... I like dynamic: https://github.com/facebook/folly/blob/master/folly/docs/Dynamic.md https://github.com/facebook/folly/blob/master/folly/docs/Dyn...
- slug 14y agoAren't most of these already within boost or recent C++ standard ? I just took a look at the format and dynamic cases.
- shin_lao 14y agoSome of them. For example Boost.Spirit.Karma is an order of magnitude faster than sprintf (I don't know compared to fbformat), with the drawback of a very long compile time (see here: http://tinodidriksen.com/2010/02/07/cpp-convert-int-to-string-speed/ http://tinodidriksen.com/2010/02/07/cpp-convert-int-to-strin...). Arena, SmallLocks and AtomicHashMap will have to challenge Intel TBB. I submit TBB will be better, but I haven't done the benchmarks. As for the rest, some of the stuff is simply outdated. There's better stuff than Synchronized in the C++11 standard. Foreach doesn't make sense with lambdas. Some of the headers are just trivial and useless functions (MapUtil.h, IntrusiveList.h, Random.h...), etc. I'm a bit disappointed.
- chad_walters 14y agoFrom the OP: "Our primary aim with this 'foolishness' is to create a solution that allows us to continue open sourcing parts of our stack without resorting to reinventing some of our internal wheels." And: "we think C++ developers might find parts of this library interesting in their own right." I think the key thing is that these are some basic pieces that a lot of FB's internal C++ code depends on. These pieces are being made available as a stepping stone to open sourcing more significant work.
- vl 14y agoModern heaps typically have some low-fragmentation technique built-in, for example, Windows ships with Low Fragmentation Heap, which is turned on by default since Vista.
- orijing 14y agoWhat is "low-fragmentation heap"? Why would anyone want "high-fragmentation heap"? (since you imply that it's an option)
- cperciva 14y agoWhy would anyone want "high-fragmentation heap"? For short-lived processes, it's faster and uses less memory. The code is also simpler (important if you're writing a malloc in the mid-1980s).
- cpeterso 14y agoMicrosoft Low-fragmentation Heap: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366750%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/aa36...
- vl 14y agoLow-fragmentation heap puts object of similar size together, so once object is freed, this memory can be reused for other object of similar size without fragmentation. Because of this is has more "slack" - unused memory at the end of the objects that are smaller than their buckets. On other hand, application in steady state is not going slowly increase it's memory use over time. Also it puts consequently allocated objects (of different size) far away (and thus reduces cache locality), which, in turn may reduce performance for some "allocate a lot of stuff at the beginning and then serve it", etc scenarios, but this is pretty esoteric problem. Benefits outweigh the concerns, so most apps benefit from the low-fragmentation heaps.
- tptacek 14y agoThis is all pretty great stuff. Make sure you read through the docs; I'm unlikely to use Fb's C++ code, but I'm sure as hell going to look at making my C vector code do some of what FBVector does: https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md https://github.com/facebook/folly/blob/master/folly/docs/FBV...
- stianan 14y agoOut of curiosity, are you unlikely to use the code because it's C++ or because it comes from Facebook?
- tptacek 14y agoC++.
- tomjen3 14y agoI realise this is a dangerous subject, but I am genuinly curious: given the business you run and the work you do for the Freebsd team, why would you object to using c++, but not c? I could understand why you would object to both, but why only the lower level language.
- seiji 14y agoPersonally, I can't keep all of how C++ works in my brain at once. Most people end up limiting themselves to a "sane subset" of C++ to compensate for spec sprawl. But, everybody picks a different subset, so you can quickly stumble on things you think you know but don't work quite right when working on non-self-originated code.
- tptacek 14y agoI don't work for the FreeBSD team.
- cperciva 14y agogiven the business you run and the work you do for the Freebsd team Are you getting confused between tptacek and me?
- saraid216 14y agoI suppose I'll have to be the first to express shock that they decided to name it Folly. I feel like Poe's Law is expressing itself.
- andralex 14y ago"Folly" started as an internal codename loosely based on "F"acebook "O"pen source "LL"ibrar"Y". When the time to choose an official name arrived, we found "folly" too funny to not use.
- alainbryden 14y agoThis is a conspiracy theory, but what if there are bugs in it that they can't find and so they're open sourcing it in the hope that someone else will fix it.
- eliben 14y ago++ for being nicely documented
- zem 14y agoi just attended alexandrescu's talk on some of the optimisations that went into this [rami sayar liveblogged it here: http://ramisayar.com/fb-cpp-conf/ http://ramisayar.com/fb-cpp-conf/]. very interesting and inspiring remarks on instruction-level parallelism [http://en.wikipedia.org/wiki/Instruction_level_parallelism http://en.wikipedia.org/wiki/Instruction_level_parallelism] and ways to help your code achieve it.
- pjmlp 14y agoVery nice addition to my C++ toolset.
- bearwithclaws 14y agoIs the 3 "o" intentional?
- tudorb 14y agoI'm Tudor, one of the main folly authors. I wrote format, Arena / ThreadCachedArena, DiscriminatedPtr, GroupVarint, TimeoutQueue, and various other pieces (parts of String.h, ThreadLocal, etc), and I'm pretty well-versed with the entire library so I can reasonably answer questions (or poke the appropriate people to make a HN account and answer). Ask away.
- chrisaycock 14y agoNot necessarily specific to Folly, but I've wondered why vector classes don't have a "short vector optimization" like string classes do. That is, why don't they store 24 bytes or so in place? Is it because the required iterators would take-up too much space anyway?
- tudorb 14y agofolly::small_vector does just that (and it lets you use one bit for a mutex, too! -- we have a lot of memory-constrained apps so we had to design data structures for them). We might unify that with fbvector eventually.
- cpeterso 14y agoI'm surprised they used mixed-case file names when their class names are lowercase. You have to remember both capitalizations. Mixed-case file names can also be problematic when porting to case-insensitive file systems like Windows' or Mac OS X'.
- bwei 14y agoVery nice.
- tudorb 14y agoNow with discussion group: https://groups.google.com/d/forum/facebook-folly https://groups.google.com/d/forum/facebook-folly