https://github.com/agrafix/superbuffer
Haskell: Efficiently build a bytestring from smaller chunks
https://github.com/agrafix/superbuffer
Last synced: about 1 year ago
JSON representation
Haskell: Efficiently build a bytestring from smaller chunks
- Host: GitHub
- URL: https://github.com/agrafix/superbuffer
- Owner: agrafix
- License: bsd-3-clause
- Created: 2016-12-01T10:57:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-06-25T06:07:07.000Z (almost 4 years ago)
- Last Synced: 2024-04-26T01:31:01.065Z (about 2 years ago)
- Language: Haskell
- Size: 362 KB
- Stars: 24
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Haskell SuperBuffer
[](https://circleci.com/gh/agrafix/superbuffer)
[](http://hackage.haskell.org/package/superbuffer)
The `superbuffer` packages was designed to efficiently build up bytestrings from `IO` actions producing
smaller chunks. The goal was to reduce memory overhead as much as possible while still being as fast as possible.
In our use case, it reduced total memory usage of the program from `350 MB` (`bytestring` builder) to `50 MB` (`superbuffer`).
For speed see benchmarks below. Note that the speed heavily depends on a good choice of the initial buffer size. `superbuffer` outperforms or performs similar to the `bytestring` alternatives consistently. `superbuffer` outperforms `buffer-builder`.
## Usage
```haskell
{-# LANGUAGE OverloadedStrings #-}
module Example where
import Data.ByteString.SuperBuffer
import qualified Data.ByteString as BS
myBS :: IO BS.ByteString
myBS =
-- note: performance of superbuffer heavily depends on a
-- smart choice of the initial buffer size. Benchmark to
-- find what suits your needs.
withBuffer 1024 $ \buf ->
do appendBuffer buf "Hello "
appendBuffer buf "World!"
```
## Benchmarks
See: [Benchmarks for 0.3.0.0](https://agrafix.github.io/superbuffer/benchmarks-0.3.0.0.html)