unboxed-ref

Fast unboxed references for ST and IO monad https://github.com/winterland1989/unboxed-ref

Version on this page:0.4.0.0
LTS Haskell 12.14:0.4.0.0
Stackage Nightly 2018-10-21:0.4.0.0
Latest on Hackage:0.4.0.0

See all snapshots unboxed-ref appears in

BSD3 licensed by winter
Maintained by drkoster@qq.com

Module documentation for 0.4.0.0

unboxed-ref

Hackage Test Status

This package provide fast unboxed references for ST and IO monad and atomic operations for IORefU Int type. Unboxed reference is implemented using single cell MutableByteArray s to eliminate indirection overhead which MutVar# s a carry, on the otherhand unboxed reference only support limited type(instances of Prim class).

A simple diagram could show the difference between IORef Int with IORefU Int:

data Foo = Foo {-# UNPACK #-} (IORef Int)

        +-----------+    +-------------+    +---------+
        | Foo |  *  +--->+ MutVar# | * +--->+ I# | i# |
        +-----------+    +-------------+    +---------+

data Bar = Bar {-# UNPACK #-} (IORefU Int)

        +-----------+    +------------------------+
        | Bar |  *  +--->+ MutableByteArray# | i# |
        +-----------+    +------------------------+

Benchmark

Modified from this benchmark.

$ cd bench && cabal build
$ time ./dist/build/bench-ref/bench-ref
143
./dist/build/bench-ref/bench-ref  19.76s user 0.02s system 99% cpu 19.785 total
------------------------------------------------------------
$ time ./dist/build/bench-unboxed-ref/bench-unboxed-ref
143
./dist/build/bench-unboxed-ref/bench-unboxed-ref  16.66s user 0.02s system 99% cpu 16.694 total
------------------------------------------------------------
$ ./dist/build/bench-unboxed-ref-atomic/bench-unboxed-ref-atomic
50500000
------------------------------------------------------------
$ ./dist/build/bench-ref-atomic/bench-ref-atomic
3597361

Changes

Revision history for unboxed-ref

0.4.0.0 – 2017-07-17

  • Add atomic operations which return old value, which is useful for building concurrent control structures.
Depends on 3 packages:
Used by 1 package:
comments powered byDisqus