folly/

Introduction

Folly (acronymed loosely after Facebook Open Source Library) is a library of C++11 components designed with practicality and efficiency in mind. It complements (as opposed to competing against) offerings such as Boost and of course std. In fact, we embark on defining our own component only when something we need is either not available, or does not meet the needed performance profile.

Performance concerns permeate much of Folly, sometimes leading to designs that are more idiosyncratic than they would otherwise be. Good performance at large scale is a unifying theme in all of Folly.

Logical Design

Folly is a collection of relatively independent components, some as simple as a few symbols. There is no restriction on internal dependencies, meaning that a given folly module may use any other folly components.

All symbols are defined in the top-level namespace folly, except of course macros. Macro names are ALL_UPPERCASE. Namespace folly defines other internal namespaces such as internal or detail. User code should not depend on symbols in those namespaces.

Physical Design

At the top level Folly uses the classic “stuttering” scheme folly/folly used by Boost and others. The first directory serves as an installation root of the library (with possible versioning a la folly-1.0/), and the second is to distinguish the library when including files, e.g. #include <folly/FBString.h>.

The directory structure is flat (mimicking the namespace structure), i.e. we don't have an elaborate directory hierarchy (it is possible this will change in future versions).

The folly/folly/test subdirectory includes the unittests for all components, usually named ComponentXyzTest.cpp for each ComponentXyz.*. The folly/folly/docs directory contains documentation.

Compatibility

Currently, folly has been tested on gcc 4.6 on 64-bit installations of Fedora 17, Ubuntu 12.04, and Debian wheezy. It might work unmodified on other 64-bit Linux platforms.

Components

Below is a list of Folly components in alphabetical order, along with a brief description of each.

Benchmark.h

A small framework for benchmarking code. Client code registers benchmarks, optionally with an argument that dictates the scale of the benchmark (iterations, working set size etc). The framework runs benchmarks (subject to a command-line flag) and produces formatted output with timing information.

Bits.h

Various bit manipulation utilities optimized for speed; includes functions that wrap the ffsl(l) primitives in a uniform interface.

Conv.h

A variety of data conversion routines (notably to and from string), optimized for speed and safety.

dynamic.h

Dynamically-typed object, created with JSON objects in mind.

Endian.h

Endian conversion primitives.

####Escape.h

Escapes a string in C style.

####eventfd.h

Wrapper around the eventfd system call.

####FBString.h

A drop-in implementation of std::string with a variety of optimizations.

####FBVector.h

A mostly drop-in implementation of std::vector with a variety of optimizations.

####Foreach.h

Pseudo-statements (implemented as macros) for iteration.

####Format.h

Python-style formatting utilities.

####Hash.h

Various popular hash function implementations.

####Histogram.h

A simple class for collecting histogram data.

####Likely.h

Wrappers around __builtin_expect.

####Malloc.h

Memory allocation helpers, particularly when using jemalloc.

####MapUtil.h

Helpers for finding items in associative containers (such as std::map and std::unordered_map).

####Preprocessor.h

Necessarily evil stuff.

####PrettyPrint.h

Pretty-printer for numbers that appends suffixes of unit used: bytes (kb, MB, ...), metric suffixes (k, M, G, ...), and time (s, ms, us, ns, ...).

####Random.h

Defines only one function---randomNumberSeed().

####Range.h

Boost-style range facility and the StringPiece specialization.

####ScopeGuard.h

C++11 incarnation of the old ScopeGuard idiom.

####SmallLocks.h

Very small spin locks (1 byte and 1 bit).

####StlAllocator.h

STL allocator wrapping a simple allocate/deallocate interface.

####String.h

String utilities that connect folly::fbstring with std::string.

####System.h

Demangling and errno utilities.

####ThreadCachedInt.h

High-performance atomic increment using thread caching.

####ThreadLocal.h

Improved thread local storage for non-trivial types.

####Traits.h

Type traits that complement those defined in the standard C++11 header <traits>.