Scripts2026年7月6日·1 分钟阅读

Folly — Facebook's High-Performance C++ Foundation Library

Folly is Facebook's open-source C++ library providing core utilities for large-scale systems including futures, concurrency primitives, string handling, and memory management. It complements the C++ standard library with production-tested components optimized for performance.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Folly Overview
直接安装命令
npx -y tokrepo@latest install 85688bf6-7978-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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-in std::string replacement) and fbvector
  • Supplies memory allocation helpers, custom allocators, and arena-based allocation for latency-sensitive code
  • Includes IO utilities such as IOBuf for zero-copy buffer management and AsyncSocket for 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=ON to 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 fbstring implementation with small-string optimization and copy-on-write semantics
  • folly::Future provides a composable async model with .then() chaining and executor awareness
  • IOBuf enables 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.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产