Skip to content

Folly (Meta) Source-Level Deep Analysis

Folly is Meta's (formerly Facebook) C++ foundation library. Source code is located at references/impl/folly/folly/.

Folly's core components cover strings, hash tables, zero-copy buffers, async frameworks, and thread-safe containers—each more thoughtfully designed than its standard library counterpart.

Table of Contents

ChapterSource PathContent
fbstring Three-Tier StorageFBString.hSmall/Medium/Large three tiers, COW reference counting, page-crossing optimization
F14 Hash Tablecontainer/F14*.hChunk-based layout, SIMD tag probing, comparison with SwissTable
IOBuf Zero-Copy BufferIOBuf.hCircular doubly-linked list, reference counting, custom free callbacks
Future/Promise Async Frameworkfutures/Future.h, Promise.hCore shared state, four-state machine, SemiFuture/Future, Executor
Synchronized and ToolsSynchronized.h, Function.hType-safe lock guards, move-only Function SBO

Standard Library Comparison Overview

ComponentFollyStandard LibraryKey Difference
stringfbstring three-tier (Small/Medium/Large COW)std::string two-tier (Small/Long)SSO=23 vs 15/22
hash_mapF14 (chunk + SIMD)unordered_map (node-based chaining)F14 is more cache-friendly
byte_bufferIOBuf (reference counting + chained)vector<char> (copy semantics)Zero-copy
asyncFuture/Promise + Executorstd::future (blocking)Full continuation support
thread_safeSynchronized<T> (RAII)Manual mutex + lock_guardCompile-time enforced locking
callablefolly::Function (SBO, move-only)std::function (SBO, copy-only)Supports move-only

Released under the MIT License