Find a file
Marcin Kowalczyk 984b191f0f Fix the remaining occurrence of non-const std::string::data().
PiperOrigin-RevId: 479818960
2022-10-08 21:59:12 +02:00
.github/workflows Switch CI to GitHub Actions. 2021-09-01 16:57:31 +00:00
cmake Merge pull request #133 from JunHe77:simd 2021-08-30 01:36:24 +00:00
docs The snappy landing page at http://google.github.io/snappy/ is 2019-05-16 11:11:34 -07:00
testdata Fix public issue 82: Stop distributing benchmark data files that have 2014-02-19 10:31:49 +00:00
third_party Fixup for adding the third_party/{benchmark, googletest} submodules. (#115) 2020-12-15 12:01:28 -08:00
.gitignore Fully qualify std::string. 2019-09-26 10:57:29 -07:00
.gitmodules Remove custom testing and benchmarking code. 2020-12-14 21:27:31 +00:00
AUTHORS Revision created by MOE tool push_codebase. 2011-03-18 17:14:15 +00:00
CMakeLists.txt Add config and header file for NEON support 2021-08-12 15:45:46 +08:00
CONTRIBUTING.md Update contributing guidelines. 2022-01-12 17:25:50 +00:00
COPYING Change some internal path names. 2015-06-22 15:39:08 +02:00
format_description.txt In the format description, use a clearer example to emphasize that varints are 2011-10-05 12:27:12 +00:00
framing_format.txt Add support for padding in the Snappy framed format. 2013-10-25 13:31:27 +00:00
NEWS Tag open source release 1.1.9. 2021-05-04 22:53:34 +00:00
README.md Update contributing guidelines. 2022-01-12 17:25:50 +00:00
snappy-c.cc Include C bindings of Snappy, contributed by Martin Gieseking. 2011-04-08 09:51:53 +00:00
snappy-c.h Change some internal path names. 2015-06-22 15:39:08 +02:00
snappy-internal.h Optimize Zippy compression for ARM by 5-10% by choosing csel instructions 2022-05-09 16:19:11 +00:00
snappy-sinksource.cc Fix Clang/GCC compilation warnings. 2020-05-05 16:15:02 +00:00
snappy-sinksource.h Merge pull request #107 from jsteemann:bug-fix/fix-compile-warning 2020-11-03 20:51:55 +00:00
snappy-stubs-internal.cc Migrate to standard integral types. 2020-04-12 20:10:03 +00:00
snappy-stubs-internal.h Migrate feature detection macro checks from #ifdef to #if. 2021-08-16 18:26:33 +00:00
snappy-stubs-public.h.in Remove #include <string> from snappy-stubs-public.h. 2020-04-14 16:50:30 +00:00
snappy-test.cc Migrate feature detection macro checks from #ifdef to #if. 2021-08-16 18:26:33 +00:00
snappy-test.h Migrate feature detection macro checks from #ifdef to #if. 2021-08-16 18:26:33 +00:00
snappy.cc Fix compilation errors under C++11. 2022-10-08 08:41:35 +02:00
snappy.h Add snappy::CompressFromIOVec. 2022-09-29 09:32:28 -07:00
snappy_benchmark.cc Fix compilation errors under C++11. 2022-10-08 08:41:35 +02:00
snappy_compress_fuzzer.cc Switch from C headers to C++ headers. 2020-04-29 19:38:03 +00:00
snappy_test_data.cc Split benchmarks and test tools into separate targets. 2020-12-16 19:09:56 +00:00
snappy_test_data.h Split benchmarks and test tools into separate targets. 2020-12-16 19:09:56 +00:00
snappy_test_tool.cc Migrate feature detection macro checks from #ifdef to #if. 2021-08-16 18:26:33 +00:00
snappy_uncompress_fuzzer.cc Switch from C headers to C++ headers. 2020-04-29 19:38:03 +00:00
snappy_unittest.cc Fix the remaining occurrence of non-const std::string::data(). 2022-10-08 21:59:12 +02:00

Snappy, a fast compressor/decompressor.

Build Status

Introduction

Snappy is a compression/decompression library. It does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression. For instance, compared to the fastest mode of zlib, Snappy is an order of magnitude faster for most inputs, but the resulting compressed files are anywhere from 20% to 100% bigger. (For more information, see "Performance", below.)

Snappy has the following properties:

  • Fast: Compression speeds at 250 MB/sec and beyond, with no assembler code. See "Performance" below.
  • Stable: Over the last few years, Snappy has compressed and decompressed petabytes of data in Google's production environment. The Snappy bitstream format is stable and will not change between versions.
  • Robust: The Snappy decompressor is designed not to crash in the face of corrupted or malicious input.
  • Free and open source software: Snappy is licensed under a BSD-type license. For more information, see the included COPYING file.

Snappy has previously been called "Zippy" in some Google presentations and the like.

Performance

Snappy is intended to be fast. On a single core of a Core i7 processor in 64-bit mode, it compresses at about 250 MB/sec or more and decompresses at about 500 MB/sec or more. (These numbers are for the slowest inputs in our benchmark suite; others are much faster.) In our tests, Snappy usually is faster than algorithms in the same class (e.g. LZO, LZF, QuickLZ, etc.) while achieving comparable compression ratios.

Typical compression ratios (based on the benchmark suite) are about 1.5-1.7x for plain text, about 2-4x for HTML, and of course 1.0x for JPEGs, PNGs and other already-compressed data. Similar numbers for zlib in its fastest mode are 2.6-2.8x, 3-7x and 1.0x, respectively. More sophisticated algorithms are capable of achieving yet higher compression rates, although usually at the expense of speed. Of course, compression ratio will vary significantly with the input.

Although Snappy should be fairly portable, it is primarily optimized for 64-bit x86-compatible processors, and may run slower in other environments. In particular:

  • Snappy uses 64-bit operations in several places to process more data at once than would otherwise be possible.
  • Snappy assumes unaligned 32 and 64-bit loads and stores are cheap. On some platforms, these must be emulated with single-byte loads and stores, which is much slower.
  • Snappy assumes little-endian throughout, and needs to byte-swap data in several places if running on a big-endian platform.

Experience has shown that even heavily tuned code can be improved. Performance optimizations, whether for 64-bit x86 or other platforms, are of course most welcome; see "Contact", below.

Building

You need the CMake version specified in CMakeLists.txt or later to build:

git submodule update --init
mkdir build
cd build && cmake ../ && make

Usage

Note that Snappy, both the implementation and the main interface, is written in C++. However, several third-party bindings to other languages are available; see the home page for more information. Also, if you want to use Snappy from C code, you can use the included C bindings in snappy-c.h.

To use Snappy from your own C++ program, include the file "snappy.h" from your calling file, and link against the compiled library.

There are many ways to call Snappy, but the simplest possible is

snappy::Compress(input.data(), input.size(), &output);

and similarly

snappy::Uncompress(input.data(), input.size(), &output);

where "input" and "output" are both instances of std::string.

There are other interfaces that are more flexible in various ways, including support for custom (non-array) input sources. See the header file for more information.

Tests and benchmarks

When you compile Snappy, the following binaries are compiled in addition to the library itself. You do not need them to use the compressor from your own library, but they are useful for Snappy development.

  • snappy_benchmark contains microbenchmarks used to tune compression and decompression performance.
  • snappy_unittests contains unit tests, verifying correctness on your machine in various scenarios.
  • snappy_test_tool can benchmark Snappy against a few other compression libraries (zlib, LZO, LZF, and QuickLZ), if they were detected at configure time. To benchmark using a given file, give the compression algorithm you want to test Snappy against (e.g. --zlib) and then a list of one or more file names on the command line.

If you want to change or optimize Snappy, please run the tests and benchmarks to verify you have not broken anything.

The testdata/ directory contains the files used by the microbenchmarks, which should provide a reasonably balanced starting point for benchmarking. (Note that baddata[1-3].snappy are not intended as benchmarks; they are used to verify correctness in the presence of corrupted data in the unit test.)

Contributing to the Snappy Project

In addition to the aims listed at the top of the README Snappy explicitly supports the following:

  1. C++11
  2. Clang (gcc and MSVC are best-effort).
  3. Low level optimizations (e.g. assembly or equivalent intrinsics) for:
  4. x86
  5. x86-64
  6. ARMv7 (32-bit)
  7. ARMv8 (AArch64)
  8. Supports only the Snappy compression scheme as described in format_description.txt.
  9. CMake for building

Changes adding features or dependencies outside of the core area of focus listed above might not be accepted. If in doubt post a message to the Snappy discussion mailing list.

We are unlikely to accept contributions to the build configuration files, such as CMakeLists.txt. We are focused on maintaining a build configuration that allows us to test that the project works in a few supported configurations inside Google. We are not currently interested in supporting other requirements, such as different operating systems, compilers, or build systems.

Contact

Snappy is distributed through GitHub. For the latest version and other information, see https://github.com/google/snappy.