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.
84 Bit-twiddling functions that wrap the
85 [ffsl(l)](http://linux.die.net/man/3/ffsll) primitives in a uniform
88 #### `ConcurrentSkipList.h`
90 An implementation of the structure described in [A Provably Correct
91 Scalable Concurrent Skip
92 List](http://www.cs.tau.ac.il/~shanir/nir-pubs-web/Papers/OPODIS2006-BA.pdf)
95 #### [`Conv.h`](Conv.md)
97 A variety of data conversion routines (notably to and from string),
98 optimized for speed and safety.
100 #### `DiscriminatedPtr.h`
102 Similar to `boost::variant`, but restricted to pointers only. Uses the
103 highest-order unused 16 bits in a pointer as discriminator. So
104 `sizeof(DiscriminatedPtr<int, string, Widget>) == sizeof(void*)`.
106 #### [`dynamic.h`](Dynamic.md)
108 Dynamically-typed object, created with JSON objects in mind.
112 Endian conversion primitives.
116 Escapes a string in C style.
121 [`eventfd`](http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html)
124 ####[`FBString.h`](FBString.md)
126 A drop-in implementation of `std::string` with a variety of optimizations.
128 ####[`FBVector.h`](FBVector.md)
130 A mostly drop-in implementation of `std::vector` with a variety of
135 Pseudo-statements (implemented as macros) for iteration.
137 ####[`Format.h`](Format.md)
139 Python-style formatting utilities.
141 ####[`GroupVarint.h`](GroupVarint.md)
144 encoding](http://www.ir.uwaterloo.ca/book/addenda-06-index-compression.html)
149 Various popular hash function implementations.
151 ####[`Histogram.h`](Histogram.md)
153 A simple class for collecting histogram data.
155 ####`IntrusiveList.h`
157 Convenience type definitions for using `boost::intrusive_list`.
161 JSON serializer and deserializer. Uses `dynamic.h`.
165 Wrappers around [`__builtin_expect`](http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html).
169 Memory allocation helpers, particularly when using jemalloc.
173 Helpers for finding items in associative containers (such as
174 `std::map` and `std::unordered_map`).
176 ####[`PackedSyncPtr.h`](PackedSyncPtr.md)
178 A highly specialized data structure consisting of a pointer, a 1-bit
179 spin lock, and a 15-bit integral, all inside one 64-bit word.
183 Necessarily evil stuff.
187 Pretty-printer for numbers that appends suffixes of unit used: bytes
188 (kb, MB, ...), metric suffixes (k, M, G, ...), and time (s, ms, us,
191 ####[`ProducerConsumerQueue.h`](ProducerConsumerQueue.md)
193 Lock free single-reader, single-writer queue.
197 Defines only one function---`randomNumberSeed()`.
201 Boost-style range facility and the `StringPiece` specialization.
205 Fast and compact reader-writer spin lock.
209 C++11 incarnation of the old [ScopeGuard](http://drdobbs.com/184403758) idiom.
211 ####[`SmallLocks.h`](SmallLocks.md)
213 Very small spin locks (1 byte and 1 bit).
217 Vector with the small buffer optimization and an ptional embedded
220 ####`sorted_vector_types.h`
222 Collections similar to `std::map` but implemented as sorted vectors.
226 STL allocator wrapping a simple allocate/deallocate interface.
230 String utilities that connect `folly::fbstring` with `std::string`.
232 ####[`Synchronized.h`](Synchronized.md)
234 High-level synchronization library.
238 Demangling and errno utilities.
240 ####[`ThreadCachedInt.h`](ThreadCachedInt.md)
242 High-performance atomic increment using thread caching.
244 ####[`ThreadLocal.h`](ThreadLocal.md)
246 Improved thread local storage for non-trivial types.
250 Queue with per-item timeout.
254 Type traits that complement those defined in the standard C++11 header
259 Defines the `codePointToUtf8` function.