Commit Graph

24 Commits

Author SHA1 Message Date
Jacek Sieka 7cb2e57a58
snappy revamp (#10)
This is a more or less complete revamp of the snappy library aiming to:

* clear out a lot of the duplicate code
* remove some of the redundant API
* unify the codebase behind a single, optimized "inner" encoder/decoder
* unify the public API for in-memory and stream
compression/decompression
* improve performance

As such, only the documented API remains backwards-compatible - the rest
has been refactored, moved around and rewritten:

* `import snappy` now exposes only in-memory encoders / decoders
* framed format moved to `snappy` module, `snappy/framing` removed
* faststreams integration moved to `snappy/faststreams`
* minimal `std/streams` integration started in `snappy/streams`

Other changes include:

* up-to-date documentation
* allocation- and exception-free API (uses some amount of stack memory)
* a 2-3x improvement to both compression and decompression performance,
putting the library mostly on par with the C++ implementation (see
README)
* the implementation was heavily inspired by the `C++`, `C` and `go`
implementations, but somewhat simplified
* nonetheless, the code uses a significant amount of unsafe code to
work around inefficiencies in the safe subset of Nim

With bulk operations in place, the cost of range checks falls
significantly - we can reintroduce them without any significant loss in
performance by carefully ordering operations such that optimizers can
elide most.
2022-04-14 16:22:41 +02:00
Jacek Sieka 16bf7b7d96
deduplicate and reorganise code (#9)
The snappy codebase is a mess with competing implementations,
nonsensical code duplication and no real direction due to a partially
implemented faststreams migration.

This PR makes it slightly less of a mess, but make no mistake, it's
still a mess - the difference being that there are a few more signposts
along the way in terms of module organisation, and a little less mess as
the line count of the PR discloses.

Performance remains poor - ~3x slower than C++ - but at least there's
less code to look at :)
2022-04-01 12:57:39 +02:00
Etan Kissling 16cce7d07c fix `appendSnappyBytes` index computation
The `appendSnappyBytes` implementation of `snappy` computes indices
incorrectly, resulting in wrong data being produced. The implementation
was fixed and the test suite extended accordingly. Note that this issue
is not reachable because `appendSnappyBytes` is only used in test code.
2021-12-14 23:19:24 +07:00
Etan Kissling d555230013 avoid unnecessary compression of short payloads
When using `framingFormatCompress`, the given payload is compressed to
determine whether its compressed form is shorter than its raw form.
For short payloads the Snappy compression will never be shorter, so it
is not necessary to compress such payloads. Instead, short payloads can
always be treated as uncompressable data. This patch optimizes for that.
2021-12-14 23:18:34 +07:00
jangko 22dbb2eb65
fixes fishy and dubious codes 2021-02-03 19:17:19 +07:00
Jacek Sieka 5a8166b786 use stew/leb128 2020-12-15 17:07:58 +02:00
Jacek Sieka 07cea69de5
fix unnecessary seq allocation
this significantly slows down the implementation
2020-08-26 15:52:15 +02:00
Zahary Karadjov 1e506c80a9
Remove some unused code 2020-08-19 14:19:51 +03:00
Zahary Karadjov 6da2be2564
Fix a logical typo 2020-08-19 13:26:18 +03:00
Zahary Karadjov a368549c1a
Fix various integer overflow issues found through fuzzing 2020-08-18 23:11:42 +03:00
Zahary Karadjov f449a5a47a
Allow bounding the maximum decoded size 2020-08-18 17:34:55 +03:00
Zahary Karadjov f6a87764a3
Added fuzzing tests 2020-05-20 21:06:13 +03:00
Zahary Karadjov 5e9e2a1f65
Async version of the Snappy framing format based on the latest FastStreams version 2020-05-06 00:35:55 +03:00
Zahary Karadjov 80cff583e3
More faststrams upgrades; Re-enable the file-based tests 2020-04-14 17:00:40 +03:00
Zahary Karadjov b5196c17b6
Use the latest faststreams OutputStream API 2020-04-13 15:02:41 +03:00
andri lim f08cbf9dc5 working snappy framing compress prototype 2020-04-01 22:35:57 +03:00
andri lim 73bb7db070 working framing uncompress prototype 2020-04-01 22:35:57 +03:00
andri lim aafdb7c8e6 move maxEncodedLen to snappy/utils.nim 2020-04-01 22:35:57 +03:00
andri lim 68857f7b14 remove not needed import 2019-09-03 12:32:26 +03:00
andri lim 4378d9fc93 make test green 2019-09-03 12:32:26 +03:00
Zahary Karadjov 072c5eee43
Add an imlementation based on Nim std streams 2019-07-08 17:00:08 +03:00
Zahary Karadjov 185a0bb769
Migrate to faststreams; WIP benchmark 2019-07-07 15:33:25 +03:00
andri lim 25f9315c34 add compress/uncompress alias 2018-11-02 20:36:21 +07:00
andri lim 6fcbbfbab2 initial commit 2018-11-02 12:10:58 +07:00