Introduction
Folly (Facebook Open Source Library) is an open-source C++ library developed at Meta that provides core building blocks for high-performance systems programming. It supplements the C++ standard library with components that have been hardened through years of production use at one of the world's largest-scale infrastructures.
What Folly Does
- Provides high-performance concurrent data structures like
ConcurrentHashMap,AtomicHashMap, and lock-free queues - Implements a futures and promises framework (
folly::Future) for composable asynchronous programming - Offers optimized string utilities including
fbstring(a drop-instd::stringreplacement) andfbvector - Supplies memory allocation helpers, custom allocators, and arena-based allocation for latency-sensitive code
- Includes IO utilities such as
IOBuffor zero-copy buffer management andAsyncSocketfor event-driven networking
Architecture Overview
Folly is organized as a modular collection of largely independent components built on top of C++17. Each module addresses a specific systems-programming concern, from low-level bit manipulation and hardware intrinsics up through higher-level abstractions like EventBase for event loops and Executor for task scheduling. The library relies on a thin portability layer to support Linux, macOS, and Windows, and integrates with other Meta open-source projects like Fizz (TLS) and Wangle (networking framework).
Self-Hosting & Configuration
- Build requires CMake 3.0.2+, a C++17-capable compiler (GCC 7+ or Clang 6+), Boost, and several system libraries
- Install dependencies on Ubuntu:
sudo apt install libboost-all-dev libevent-dev libdouble-conversion-dev libgoogle-glog-dev libgflags-dev - Use
-DBUILD_SHARED_LIBS=ONto produce shared libraries instead of static - Individual components can be consumed via
find_package(folly)after installation - Vcpkg and Conan packages are available for cross-platform dependency management
Key Features
- Battle-tested at Meta scale across billions of requests per day
- Optimized
fbstringimplementation with small-string optimization and copy-on-write semantics folly::Futureprovides a composable async model with.then()chaining and executor awarenessIOBufenables zero-copy networking with reference-counted buffer chains- Comprehensive benchmarking utilities (
folly::Benchmark) for micro-benchmarking C++ code
Comparison with Similar Tools
- Abseil (Google) — focuses on standard-library extensions with ABI stability; Folly targets raw performance with less ABI concern
- Boost — broader scope and committee-track focus; Folly is more opinionated and Meta-specific
- POCO — provides higher-level application frameworks; Folly stays closer to systems-level primitives
- libcds — specializes in concurrent data structures; Folly offers concurrency plus general utilities
- Intel TBB — focuses on parallelism and task scheduling; Folly covers a wider utility surface
FAQ
Q: Does Folly require the entire library to be linked?
A: No. Folly is modular, and you can link only the components you need via CMake targets such as Folly::folly or individual sub-libraries.
Q: Is Folly ABI-stable? A: Folly does not guarantee ABI stability across releases. It is designed to be built from source alongside your project.
Q: What platforms does Folly support? A: Folly officially supports Linux (primary), macOS, and Windows. Linux receives the most testing and optimization.
Q: How does folly::Future differ from std::future?
A: folly::Future supports .then() continuation chaining, executor-based scheduling, and composability features like collectAll that std::future lacks.