본문으로 건너뛰기
Folly Code Review · 0/1

Folly Code Review — Meta의 production-grade C++ 라이브러리 코드 분석

· Hawk · 8분 읽기

#이 시리즈를 쓰는 이유

Meta는 수십억 사용자 트래픽을 처리하는 fbcode mono-repo에서 C++ 라이브러리를 만들었고, 그 중 외부에 공개해도 무방한 부분이 Folly다. 이름은 “Facebook Open-source LibrarY”의 약자지만, 실제로는 production에서 std로는 부족한 부분을 채워 넣은 도구 모음이다.

Folly는 Abseil과 비교되는 일이 많다. 둘 다 std::을 보완하지만 철학이 다르다. Abseil이 std 호환을 유지하면서 보완한다면, Folly는 성능을 위해서라면 std와 다른 모양도 감수한다. fbstring의 SSO+COW, F14 map의 SIMD probing, fibers의 M

coroutine 모델은 모두 그런 결정의 산물이다.

이 시리즈는 Folly의 컴포넌트를 사용법으로 훑지 않는다. Meta가 사내에서 무엇을 보고 받아들였는가, 즉 이 API가 std와 다른지, 언제 쓰면 std보다 빨라지고 언제 잘못 쓰면 더 느려지는지를 함께 본다.

#대상 독자

  • C++ 중급 이상 — std::vector, std::unique_ptr, std::function에 익숙한 사람
  • 비동기/병행 코드를 자주 다루는 시니어 엔지니어 (Future, Executor가 핵심)
  • 메모리/네트워크 성능에 민감한 시스템을 만드는 사람 (IOBuf)
  • “folly::dynamic은 std::any와 뭐가 달라?”가 궁금한 사람

C++ 초심자는 먼저 Effective Modern C++ 시리즈를 권한다.

#시리즈 구성

14 Parts × 63편으로 구성된다.

Part제목핵심편수
1Foundations설계 철학, fbcode, API stability5
2Future / Asyncfolly::Future, Promise, SemiFuture7
3ExecutorInline, CPU, IO, Manual, EventBase5
4IOBuf & Memoryzero-copy buffer chain5
5Strings (FBString)SSO + COW, fmt, StringPiece4
6Convfolly::to / tryTo3
7F14 MapsSIMD-probed hash map5
8ContainerSmallVector, AtomicHashMap, LRU5
9SynchronizationSynchronized, Baton, SharedMutex5
10Concurrency PrimitivesSPSC/MPMC queue, fiber channel4
11Dynamic Typingfolly::dynamic, JSON, visitor4
12Singleton / Factoryfolly::Singleton, vault3
13UtilityExceptionWrapper, ScopeGuard, Function5
14Code Review LessonsMeta style, anti-patterns, std vs folly3

#Part 1 — Foundations (5)

Folly가 왜 존재하는지, Abseil과의 차이부터.

#글 제목
1-01Folly 개요 — Meta가 production에서 검증한 utility
1-02Folly vs Abseil 철학 차이 (performance-first vs std-compatible)
1-03Build / fbcode 환경
1-04API stability 정책
1-05Production validation 문화

#Part 2 — Future / Async (7)

#글 제목
2-01folly::Future 개요
2-02Promise / makeFuture
2-03SemiFuture vs Future (executor binding)
2-04.then / .thenValue / .thenError
2-05collect / collectAll / collectAny
2-06retry / window / via
2-07fibers (M
coroutine)

#Part 3 — Executor (5)

#글 제목
3-01InlineExecutor
3-02CPUThreadPoolExecutor
3-03IOThreadPoolExecutor (libevent 기반)
3-04ManualExecutor (deterministic 테스트)
3-05EventBase

#Part 4 — IOBuf & Memory (5)

#글 제목
4-01IOBuf — 비복사 buffer chain
4-02IOBufQueue
4-03Cursor (read/write)
4-04Zero-copy 패턴
4-05IOBuf shared semantics

#Part 5 — Strings (FBString) (4)

#글 제목
5-01FBString — SSO + COW
5-02fmt::format integration
5-03StringPiece (string_view 호환)
5-04Join / split utilities

#Part 6 — Conv (3)

#글 제목
6-01folly::to / tryTo (text↔num 변환)
6-02Customization (사용자 타입)
6-03Performance vs sprintf / stringstream

#Part 7 — F14 Maps (5)

#글 제목
7-01F14ValueMap vs std::unordered_map
7-02F14NodeMap (stable pointer)
7-03F14VectorMap (cache-friendly iteration)
7-04F14FastMap (auto-select)
7-05F14 internals (SIMD probing)

#Part 8 — Container (5)

#글 제목
8-01SmallVector (inline storage)
8-02FixedString (compile-time string)
8-03AtomicHashMap (lock-free read)
8-04ConcurrentHashMap (sharded)
8-05EvictingCacheMap (LRU)

#Part 9 — Synchronization (5)

#글 제목
9-01Synchronized (lock wrapper)
9-02SharedMutex
9-03Baton (one-shot wait)
9-04RWSpinLock
9-05PicoSpinLock (1-byte spinlock)

#Part 10 — Concurrency Primitives (4)

#글 제목
10-01ProducerConsumerQueue (SPSC)
10-02MPMCQueue
10-03UnboundedQueue
10-04fibers::Channel

#Part 11 — Dynamic Typing (4)

#글 제목
11-01folly::dynamic
11-02JSON conversion (toJson / parseJson)
11-03Dynamic ↔ struct
11-04Visitor pattern

#Part 12 — Singleton / Factory (3)

#글 제목
12-01Singleton vs Meyers / static
12-02SingletonVault
12-03try_get / try_get_fast (성능)

#Part 13 — Utility (5)

#글 제목
13-01ExceptionWrapper
13-02ScopeGuard / SCOPE_EXIT
13-03folly::Optional (vs std::optional)
13-04folly::Function (vs std::function)
13-05Lazy

#Part 14 — Code Review Lessons (3)

#글 제목
14-01Meta 스타일 code review
14-02Folly anti-patterns (잘못 쓰면 std보다 느림)
14-03std vs folly 선택 기준

#자매 시리즈

이 시리즈와의 차이: 위 셋은 언어 feature를 다루고, 이 시리즈는 industrial library를 reading lens로 다룬다. Folly와 Abseil은 같은 문제에 다른 답을 내놓은 라이브러리다. 둘을 나란히 읽으면 production C++의 트레이드오프가 보인다.

#학습 로드맵

처음부터 1편씩 순서대로 읽지 않아도 된다. 권장 순서:

  1. 핵심 (먼저) — Part 2 (Future), Part 3 (Executor), Part 9 (Synchronization). 비동기/병행이 Folly의 가장 강력한 영역.
  2. 고성능 자료구조 — Part 7 (F14), Part 4 (IOBuf), Part 10 (Concurrency Primitives).
  3. 유틸리티 — Part 13 (ExceptionWrapper, ScopeGuard) — 다른 곳에서 흔히 빠진 것.
  4. 선택적 — Part 11 (dynamic), Part 12 (Singleton) — 필요할 때만.
  5. Part 14 — 모든 Part를 본 후 — std vs folly 의사결정.

#관련 항목