6 Folly (acronymed loosely after Facebook Open Source Library) is a
7 library of C++11 components designed with practicality and efficiency
8 in mind. It complements (as opposed to competing against) offerings
9 such as Boost and of course `std`. In fact, we embark on defining our
10 own component only when something we need is either not available, or
11 does not meet the needed performance profile.
13 Performance concerns permeate much of Folly, sometimes leading to
14 designs that are more idiosyncratic than they would otherwise be (see
15 e.g. `PackedSyncPtr.h`, `SmallLocks.h`). Good performance at large
16 scale is a unifying theme in all of Folly.
20 Folly is a collection of relatively independent components, some as
21 simple as a few symbols. There is no restriction on internal
22 dependencies, meaning that a given folly module may use any other
25 All symbols are defined in the top-level namespace `folly`, except of
26 course macros. Macro names are ALL_UPPERCASE. Namespace `folly`
27 defines other internal namespaces such as `internal` or `detail`. User
28 code should not depend on symbols in those namespaces.
32 At the top level Folly uses the classic "stuttering" scheme
33 `folly/folly` used by Boost and others. The first directory serves as
34 an installation root of the library (with possible versioning a la
35 `folly-1.0/`), and the second is to distinguish the library when
36 including files, e.g. `#include "folly/FBString.h"`.
38 The directory structure is flat (mimicking the namespace structure),
39 i.e. we don't have an elaborate directory hierarchy (it is possible
40 this will change in future versions). The subdirectory `experimental`
41 contains files that are used inside folly and possibly at Facebook but
42 not considered stable enough for client use. Your code should not use
43 files in `folly/experimental` lest it may break when you update Folly.
45 The `folly/folly/test` subdirectory includes the unittests for all
46 components, usually named `ComponentXyzTest.cpp` for each
47 `ComponentXyz.*`. The `folly/folly/docs` directory contains
52 Currently, `folly` has been tested on gcc 4.6 on 64-bit installations
53 of Fedora 17, Ubuntu 12.04, and Debian wheezy. It might work unmodified
54 on other 64-bit Linux platforms.
58 Below is a list of Folly components in alphabetical order, along with
59 a brief description of each.
61 #### `Arena.h`, `ThreadCachedArena.h`
63 Simple arena for memory allocation: multiple allocations get freed all
64 at once. With threaded version.
66 #### [`AtomicHashMap.h`, `AtomicHashArray.h`](AtomicHashMap.md)
68 High-performance atomic hash map with almost lock-free operation.
70 #### [`Benchmark.h`](Benchmark.md)
72 A small framework for benchmarking code. Client code registers
73 benchmarks, optionally with an argument that dictates the scale of the
74 benchmark (iterations, working set size etc). The framework runs
75 benchmarks (subject to a command-line flag) and produces formatted
76 output with timing information.
80 Various bit manipulation utilities optimized for speed; includes functions
82 [ffsl(l)](http://linux.die.net/man/3/ffsll) primitives in a uniform
85 #### `ConcurrentSkipList.h`
87 An implementation of the structure described in [A Provably Correct
88 Scalable Concurrent Skip
89 List](http://www.cs.tau.ac.il/~shanir/nir-pubs-web/Papers/OPODIS2006-BA.pdf)
92 #### [`Conv.h`](Conv.md)
94 A variety of data conversion routines (notably to and from string),
95 optimized for speed and safety.
97 #### `DiscriminatedPtr.h`
99 Similar to `boost::variant`, but restricted to pointers only. Uses the
100 highest-order unused 16 bits in a pointer as discriminator. So
101 `sizeof(DiscriminatedPtr<int, string, Widget>) == sizeof(void*)`.
103 #### [`dynamic.h`](Dynamic.md)
105 Dynamically-typed object, created with JSON objects in mind.
109 Endian conversion primitives.
113 Escapes a string in C style.
118 [`eventfd`](http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html)
121 ####[`FBString.h`](FBString.md)
123 A drop-in implementation of `std::string` with a variety of optimizations.
125 ####[`FBVector.h`](FBVector.md)
127 A mostly drop-in implementation of `std::vector` with a variety of
132 Pseudo-statements (implemented as macros) for iteration.
134 ####[`Format.h`](Format.md)
136 Python-style formatting utilities.
138 ####[`GroupVarint.h`](GroupVarint.md)
141 encoding](http://www.ir.uwaterloo.ca/book/addenda-06-index-compression.html)
146 Various popular hash function implementations.
148 ####[`Histogram.h`](Histogram.md)
150 A simple class for collecting histogram data.
152 ####`IntrusiveList.h`
154 Convenience type definitions for using `boost::intrusive_list`.
158 JSON serializer and deserializer. Uses `dynamic.h`.
162 Wrappers around [`__builtin_expect`](http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html).
166 Memory allocation helpers, particularly when using jemalloc.
170 Helpers for finding items in associative containers (such as
171 `std::map` and `std::unordered_map`).
173 ####[`PackedSyncPtr.h`](PackedSyncPtr.md)
175 A highly specialized data structure consisting of a pointer, a 1-bit
176 spin lock, and a 15-bit integral, all inside one 64-bit word.
180 Necessarily evil stuff.
184 Pretty-printer for numbers that appends suffixes of unit used: bytes
185 (kb, MB, ...), metric suffixes (k, M, G, ...), and time (s, ms, us,
188 ####[`ProducerConsumerQueue.h`](ProducerConsumerQueue.md)
190 Lock free single-reader, single-writer queue.
194 Defines only one function---`randomNumberSeed()`.
198 Boost-style range facility and the `StringPiece` specialization.
202 Fast and compact reader-writer spin lock.
206 C++11 incarnation of the old [ScopeGuard](http://drdobbs.com/184403758) idiom.
208 ####[`SmallLocks.h`](SmallLocks.md)
210 Very small spin locks (1 byte and 1 bit).
214 Vector with the small buffer optimization and an optional embedded
217 ####`sorted_vector_types.h`
219 Collections similar to `std::map` but implemented as sorted vectors.
223 STL allocator wrapping a simple allocate/deallocate interface.
227 String utilities that connect `folly::fbstring` with `std::string`.
231 Subprocess library, modeled after Python's subprocess module.
233 ####[`Synchronized.h`](Synchronized.md)
235 High-level synchronization library.
239 Demangling and errno utilities.
241 ####[`ThreadCachedInt.h`](ThreadCachedInt.md)
243 High-performance atomic increment using thread caching.
245 ####[`ThreadLocal.h`](ThreadLocal.md)
247 Improved thread local storage for non-trivial types.
251 Queue with per-item timeout.
255 Type traits that complement those defined in the standard C++11 header
260 Defines the `codePointToUtf8` function.