TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Folly: An open-source C++ library developed and used at Facebook

95 pointsby u1tronover 3 years ago

12 comments

otover 3 years ago
Not the OP, but active user and contributor to folly, so I can add some context.<p>folly is a community effort within Meta; it doesn&#x27;t have a specific theme about what&#x27;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&#x2F;coro for coroutines).<p>Main focus is server applications, but it is also used in mobile, in particular Thrift (the serialization&#x2F;RPC infrastructure) depends on it.<p>A very personal list of favorites:<p>- experimental&#x2F;coro is the coroutines infrastructure, which is now widely adopted.<p>- SharedMutex is a heavily optimized mutex which supports shared&#x2F;upgrade&#x2F;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.<p>- DistributedMutex, OTOH, is an exclusive-only mutex that supports flat combining, and performs extremely well under high contention.<p>- MPMCQueue and UnboundedQueue are lock-free MPMC queues, respectively bounded and unbounded, which are used in almost all our thread pools (see the executor&#x2F; directory)<p>- Userland implementations of RCU and hazard pointers, for deferred reclamation.<p>- 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&#x27;re waiting long enough, they unmap the unused suffix of the stack, so idle threads don&#x27;t hold unused stack memory.<p>- 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.<p>- F14 is a SIMD-optimized hash table. Similar to Abseil&#x27;s SwissTable, it was published around the same time.<p>- TDigest is a highly scalable quantile estimator, widely used for service counters (see fb303, also open source).<p>- (shameless plug, as I wrote this one) enumerate() is a replica of the Python function, so you can do<p>for (auto&amp;&amp; [i, element] : folly::enumerate(collection)) { ... }
评论 #29849459 未加载
dfghdfhsover 3 years ago
Wouldn&#x27;t it be better to have in the title _what_ the library is supposed to achieve, as opposed to who published it?<p>Right now the title reads essentially: &quot;Here&#x27;s a library&quot;.
评论 #29842857 未加载
评论 #29843842 未加载
评论 #29843461 未加载
评论 #29843208 未加载
评论 #29843092 未加载
评论 #29843460 未加载
评论 #29844762 未加载
评论 #29843209 未加载
interroboinkover 3 years ago
I 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&#x27;s not very modular in that way.<p>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.<p>If nothing else, it&#x27;s worth reading for some of the highly-optimized stuff going on in there.
ComputerGuruover 3 years ago
See previous discussions dating all the way back to 2012:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=4059356" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=4059356</a><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22875090" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22875090</a>
评论 #29842624 未加载
zoomablemindover 3 years ago
Such a massive lib. Interesting, if not too extensive read.<p>I understand the FB rationale to have it, but what whould be a reason for other projects to adopt this lib?<p>I won&#x27;t imagine maintaining such a lib as a dependency by ourselves. Maybe for one short-term purpose, but then it&#x27;s still safer to go with standard or boost, or, God forbid, carve out some pieces and wrap them up.
评论 #29844749 未加载
alcoverover 3 years ago
Would someone point me to a C implementaion of folly&#x2F;FBString ? Or any C String OSS lib that is similar to what C++ std::string(&#x2F;wiew) does ?<p>More precisely, one that defines a datatype (no SDS-like trick) and has all goodies like SSO, CoW, views, thread-safety, etc..<p>I&#x27;m making such a lib but can&#x27;t seem to find other examples to compare.
评论 #29843124 未加载
derefnullover 3 years ago
<p><pre><code> folly [https:&#x2F;&#x2F;www.wordnik.com&#x2F;words&#x2F;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. </code></pre> 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.<p><pre><code> “acronymed loosely after Facebook Open Source Library” </code></pre> Yet why accept a name with a negative connotation.. The name leads the product, so why not at least make it _neutral_?
didipover 3 years ago
If you start a green field C++ project, would you choose Folly, Boost only, or Abseil?
评论 #29849868 未加载
评论 #29845729 未加载
评论 #29847452 未加载
lumostover 3 years ago
I&#x27;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&#x27;t want to role my own package manager or build process - why isn&#x27;t there a pip&#x2F;cargo&#x2F;mvn etc. for C++ devs?
评论 #29845889 未加载
评论 #29858562 未加载
评论 #29846057 未加载
vorhemusover 3 years ago
When 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.
cjensenover 3 years ago
Their Synchronized&lt;&gt; is a thing we also came up with to use in our code. It&#x27;s so helpful it should be part of the Standard Library.
评论 #29847130 未加载
评论 #29844499 未加载
评论 #29843067 未加载
seertaakover 3 years ago
The thing with folly is: boost.
评论 #29846846 未加载