10 ms·
Folly: An open-source C++ library developed and used at Facebook
- ComputerGuru 5y agoSee previous discussions dating all the way back to 2012: https://news.ycombinator.com/item?id=4059356 https://news.ycombinator.com/item?id=4059356 https://news.ycombinator.com/item?id=22875090 https://news.ycombinator.com/item?id=22875090
- oscargrouch 5y agoLooking again at it, its quite bigger now. I wonder how it compares to Boost and now also Abseil? (features and performance-wise)
- jsheard 5y agoFolly depends on Boost so it's more of a superset of it Which unfortunately means Folly is an extremely heavyweight dependency to pull in compared to Abseil, if you're not already using Boost
- Blackthorn 5y agoBoost doesn't feel like a heavyweight dependency. I mean, yes, Boost itself is big. But when I think a heavyweight dependency, I think of something that itself pulls in a shitton of dependencies Javascript-style. And AFAIK Boost doesn't have any dependencies.
- dundarious 5y agoTry debug anything in boost. I didn't enjoy it. It's a heavyweight dependency, all on its own.
- boardwaalk 5y agoI’m afraid that’s a very JS viewpoint. A dependency doesn’t need dependencies itself to be heavy. Start using some of the heavier weight sub-libraries and you can quickly explode your compile times. I have boost beast/asio on one project and it takes over a minute to compile one of the source files…
- ComputerGuru 5y agoBoost is (was?) considered to be such a heavy dependency (especially in the days before distribution package managers and build systems got their act together and collaborated or at least acknowledged the reciprocal efforts of one another) that it's probably single-handedly responsible for easily at least half of the so-called "NIH" libraries/ad-hoc solutions I encountered for a particular decade of my career as a C++ developer. At one point, I had a curated SVN repository of certain boost header-only includes that didn't require any sort of build integration, had no dependencies of their own (even other boost libraries), and didn't require any build system integration - and I know I wasn't the only one. The world of native software development was just so unbelievably different from that of web development - it's really no surprise developers from that lived through that era have such a hard time accepting the modern-day age of PWAs in Electron sandboxes masquerading as native programs. People that cut their teeth developing desktop software with something like Python (just as an example) instead would have a completely different perspective on all this, of course.
- synergy20 5y agoit's pretty heavy, as boost has quite some inter-dependencies, pulling one of its component can bring in a few others.
- dfghdfhs 5y agoWouldn't it be better to have in the title _what_ the library is supposed to achieve, as opposed to who published it? Right now the title reads essentially: "Here's a library".
- samhw 5y agoIt's worse than that. The GitHub title is "Folly: Facebook Open-source Library". The bolded sentence in the readme is "Folly contains a variety of core library components used extensively at Facebook". In fact, the entire first paragraph is about how it's used at Facebook. It takes about a minute to find any information at all about this library besides the fact that it's used at Facebook (by the way, did you miss that? it's used at Facebook! Facebook!!). And even that information is empty bromides about how it's "designed with practicality and efficiency in mind". Hmm, I prefer my software to be impractical and inefficient... All I take away from this is that Facebook has an irrationally optimistic expectation of how the world views its engineering prowess.
- drewda 5y agoInstead of pointing a finger at Facebook, I'd scoff at C++ and the way in which the language has grown where orgs build up their own utility libraries rather than depend on a standard library. That said, this is an issue for other languages as well. Another example: the "Google core libraries for Java": https://github.com/google/guava https://github.com/google/guava
- simplestats 5y agoYou mean because it has gotten so unreadable and vast? I've never worked with a place using C++ that didn't make their own core libraries. As a low-level language, there's almost always a way to get some performance benefit by starting from scratch for your specific case.
- ryandrake 5y agoI've also never worked in a C++ place that didn't make their own core libraries, but when you ask, their rationale for building and maintaining their own libraries (as opposed to using the Standard Library) is often very weak. It's usually based on very outdated assumptions and Cargo Cutting, such as "the STL[1] is slow (but we haven't profiled ours to prove it's faster)." Or "We need our own string type because decades ago, there was something that std::string didn't do." Or "Our founding developer didn't like templates, so he build this vast copy of the standard library but using explicit data types." (yes I've heard all of these "reasons") 1: Just calling it "the STL" is a key sign of living in the past--pretty much nobody uses the actual STL anymore: What we use is called the C++ Standard Library.
- alcover 5y agoWould someone point me to a C implementaion of folly/FBString ? Or any C String OSS lib that is similar to what C++ std::string(/wiew) does ? More precisely, one that defines a datatype (no SDS-like trick) and has all goodies like SSO, CoW, views, thread-safety, etc.. I'm making such a lib but can't seem to find other examples to compare.
- guavaNinja 5y agoThis[1] is a c-flavoured c++ STL replacement, uses minimal number of c++ features to be easy to use yet simple. We built it and use it internally where I work. It's not c but almost c, it could be useful for you [1] https://github.com/MoustaphaSaad/mn/blob/master/mn/include/mn/Str.h https://github.com/MoustaphaSaad/mn/blob/master/mn/include/m...
- alcover 5y agoThank you. You don't seem to provide a c_str() equivalent (a method that gives a pointer to or copies out a C-string) or views ? Sorry if I missed them.
- guavaNinja 5y agoWe hate getters/setters. There is `using Str = Buf<char>` if you looked into Buf you will find ptr and count and cap. You are looking for ptr
- synergy20 5y agoThis is still all in c++ correct? why not just using STL instead, am I missing something here. There are a few pure-C made STL alike containers for C that uses no c++ code at all, a random github search finds this: https://github.com/assyrianic/Harbol https://github.com/assyrianic/Harbol , there are quite a few of them just not recalling them now.
- cjensen 5y agoTheir Synchronized<> is a thing we also came up with to use in our code. It's so helpful it should be part of the Standard Library.
- secondcoming 5y agoIt looks like part of it is a similar design to something I came up with myself. Do you know if Synchronized<> protects against accidental recursive locking?
- ot 5y agoThere is no explicit protection for recursive locking. In practice, write locks will deadlock, and read lock under read lock will be fine. However, the API encourages practices that make it very hard to recursively acquire the lock (Synchronized is about access to objects, not critical sections).
- jimsimmons 5y agoWhat does it do
- jemfinch 5y agoHaving reviewed even just a few diffs with Synchronized since joining Facebook, it absolutely should not be part of the standard library (nor, I would argue, part of folly). I have found far too many cases where engineers have threading issues in their code because they're saving references to objects after .lock() has returned. Writing thread-safe code isn't easy, and it isn't made easier by libraries that offer footguns like Synchronized. It's easier to get it right with compiler thread annotations than with Synchronized.
- ot 5y agoHow do compiler thread annotations solve the problem of persisting references to the object? Is static analysis able to detect that? Seems a hard problem (basically escape analysis). Synchronized cannot guarantee thread-safety, but in my experience wrappers that do not allow unsynchronized access to the object are better than the alternative. Annotations are just another way to guard access.
- seertaak 5y agoThe thing with folly is: boost.
- crispyalmond 5y agoIt would be more attractive if it didn't depend on boost.
- ot 5y agoNot the OP, but active user and contributor to folly, so I can add some context. folly is a community effort within Meta; it doesn't have a specific theme about what's included in it, but it is a set of core libraries that are likely to be depended on by most C++ software within the company, and are enough high-quality and self-contained that they can be useful externally, or showcase implementations undergoing standardization efforts (for example experimental/coro for coroutines). Main focus is server applications, but it is also used in mobile, in particular Thrift (the serialization/RPC infrastructure) depends on it. A very personal list of favorites: - experimental/coro is the coroutines infrastructure, which is now widely adopted. - SharedMutex is a heavily optimized mutex which supports shared/upgrade/exclusive semantics, and allows near-linear scalability in shared mode. It is used pretty much everywhere as it is the default mutex for Synchronized, a wrapper to safely synchronize access to objects. Its footprint is just 4 bytes. - DistributedMutex, OTOH, is an exclusive-only mutex that supports flat combining, and performs extremely well under high contention. - MPMCQueue and UnboundedQueue are lock-free MPMC queues, respectively bounded and unbounded, which are used in almost all our thread pools (see the executor/ directory) - Userland implementations of RCU and hazard pointers, for deferred reclamation. - LifoSem and Baton are other fundamental synchronization primitives that are not available in most core C++ libraries. They do a magic trick internally, where if they're waiting long enough, they unmap the unused suffix of the stack, so idle threads don't hold unused stack memory. - Function is like std::function, but move-only, so it can hold non-copyable function objects (think lambda that captures unique_ptr). It is the vocabulary type for callbacks used in futures and executors. - F14 is a SIMD-optimized hash table. Similar to Abseil's SwissTable, it was published around the same time. - TDigest is a highly scalable quantile estimator, widely used for service counters (see fb303, also open source). - (shameless plug, as I wrote this one) enumerate() is a replica of the Python function, so you can do for (auto&& [i, element] : folly::enumerate(collection)) { ... }
- up2isomorphism 5y agoThis type of libraries often sell themselves as high performance featuring bunch of fancy practices, yet in everywhere I had seen people using them, some of the mostly inefficient code are produced, yes that includes Facebook.
- vorhemus 5y agoWhen I write a README for a library I always try to include 1-2 code samples of the highlights of said library. So the reader sees quickly what to expect.
- zoomablemind 5y agoSuch a massive lib. Interesting, if not too extensive read. I understand the FB rationale to have it, but what whould be a reason for other projects to adopt this lib? I won't imagine maintaining such a lib as a dependency by ourselves. Maybe for one short-term purpose, but then it's still safer to go with standard or boost, or, God forbid, carve out some pieces and wrap them up.
- gjulianm 5y agoI've considered it for some special things, mainly the F14 hash table because I needed a highly performant implementation (I ended up writing a custom one that takes advantage of domain knowledge to go faster). It seems that it has classes and constructs not available in other libraries. A lot of them are very specific, but at that point having a reliable, tested, fast implementation of a complex implementation might be worth the hassle of bringing in a new dependency.
- interroboink 5y agoI like a lot of things in Folly, but as others have mentioned: you have to pull in quite a lot, even if you care about only a tiny part. It's not very modular in that way. However, I did have decent success taking the classes I was interested in (CPUThreadPoolExecutor, and surrounding), stripping the library down to just those bits, and using them. Obviously a PITA to stay current with upstream, though. If nothing else, it's worth reading for some of the highly-optimized stuff going on in there.
- didip 5y agoIf you start a green field C++ project, would you choose Folly, Boost only, or Abseil?
- versatran01 5y agoabseil and part of boost
- aaaaaaaaaaab 5y agoUnless you have a compelling reason: none of them. The modern (C++17<) stdlib should cover your needs.
- sgeisenh 5y agoThe stdlib implementations of associative containers have serious drawbacks. At the very least, most projects should consider adopting absl::flat_hash_(set|map) and absl::btree_(set|map) (or similar replacements) over the stdlib containers. I am also partial to explicit error handling over exceptions, and there is a lot to like about absl::Status (and absl::StatusOr). Disclaimer: I work for Google but the views expressed are my own and don't necessarily reflect those of my employer.
- dureuill 5y agoI wouldn't start a green field C++ project if I can help it[1], but if I had to I would probably go with the standard library with maybe as little boost as possible. [1]: http://cliffle.com/blog/prefer-rust/ http://cliffle.com/blog/prefer-rust/
- lumost 5y agoI've been very interested in native C++ development for web-services and other applications. However the development experience always seems like an after thought. I really don't want to role my own package manager or build process - why isn't there a pip/cargo/mvn etc. for C++ devs?
- saidinesh5 5y agoWe do have Conan Vcpkg Cpm.cmake A lot of projects these days use conan.
- adamnemecek 5y agoWhy not just do Rust?
- exdsq 5y agoPersonally I find C++ more fun to use than Rust, even though I use Rust as part of my day job. I'd genuinely love to find a full-time C++ gig and spend the rest of my career focused on that single language. There are tons of flaws with the language, sure, but they're documented and known flaws. And best practices to get around them. This really appeals to me.
- uptownfunk 5y agoCould you share a link to any resource that explains the common flaws and workarounds in C++?
- exdsq 5y agoI'm not by my work computer but look up any of the ISO-standardised dev environments where they need to apply formal methods
- dureuill 5y agoFunny, I have a full time C++ job, and really don't see the appeal. Rust feels superior in every regards and especially dev experience. Want to exchange jobs ;-)?
- derefnull 5y agofolly [https://www.wordnik.com/words/folly] fŏl′ē noun Lack of good sense, understanding, or foresight. An act or instance of foolishness. A costly undertaking having an absurd or ruinous outcome. At the risk of starting a meta conversation (pun intended) I wonder why the team chose this name for a set of core library components. The GitHub page indicates it is a loose play on an acronym. “acronymed loosely after Facebook Open Source Library” Yet why accept a name with a negative connotation.. The name leads the product, so why not at least make it _neutral_?