bitter v0.6 - the performant bit reading library with a new faster API

36 points comagoosie

bitter v0.6 is a pretty major change in the library as the API surface
area is much slimmer and additional performance gains have been unlocked by
allowing control of when the lookahead buffer is refilled to be passed
downstream, so that one can take advantage of patterns in the data they are
decoding.

What spurred this change was a wonderful article about how
optimizing a bit reader around Fabian Giesen's articles would lead
to large gains. This got me thinking how these could be translated to rust,
as I find bit reading to be a hot-spot in a few places. So I got to work.

There's quite a bit of unsafe (ick) and there's even an unsafe API that allow
one to shoot themselves in the foot (more ick). I'm cautiously optimistic
that the performance demonstrated by miniz_oxide (a project with lots
of bit reading and zero unsafe) could mean a reduction of unsafe in bitter without
sacrificing performance.

So feel free to look at the code or play with it. I'm definitely open to
suggestions surrounding reducing unsafe and increasing performance.