HeapSize

heapsize-0.3.0.1: Determine the size of runtime data structures

Copyright | (c) Michail Pardalos
License | 3-Clause BSD-style
Maintainer | mpardalos@gmail.com
Safe Haskell | None
Language | Haskell2010

HeapSize

Description

Based on GHC.Datasize by Dennis Felsing

Synopsis

- recursiveSize :: a -> Heapsize Int
- recursiveSizeNF :: NFData a => a -> Heapsize Int
- closureSize :: a -> IO Int
- data Heapsize a
- runHeapsize :: Int -> Heapsize a -> IO (Maybe a)

# Documentation

recursiveSize :: a -> Heapsize Int #

Calculate the recursive size of GHC objects in Bytes. Note that the actual size in memory is calculated, so shared values are only counted once.

Call with `recursiveSize $! 2` to force evaluation to WHNF before calculating the size.

Call with `recursiveSize $!! "foobar"` ($!! from Control.DeepSeq) to force full evaluation before calculating the size.

This function works very quickly on small data structures, but can be slow on large and complex ones. If speed is an issue it's probably possible to get the exact size of a small portion of the data structure and then estimate the total size from that.

recursiveSizeNF :: NFData a => a -> Heapsize Int #

Calculate the recursive size of GHC objects in Bytes after calling Control.DeepSeq.force on the data structure to force it into Normal Form. Using this function requires that the data structure has an `NFData` typeclass instance.

closureSize :: a -> IO Int #

Get the *non-recursive* size of an closure in words

data Heapsize a #

#### Instances

Instances details

MonadIO Heapsize # |
Instance details Defined in HeapSize Methods liftIO :: IO a -> Heapsize a #
MonadCatch Heapsize # |
Instance details Defined in HeapSize Methods catch :: (HasCallStack, Exception e) => Heapsize a -> (e -> Heapsize a) -> Heapsize a #
MonadMask Heapsize # |
Instance details Defined in HeapSize Methods mask :: HasCallStack => ((forall a. Heapsize a -> Heapsize a) -> Heapsize b) -> Heapsize b # uninterruptibleMask :: HasCallStack => ((forall a. Heapsize a -> Heapsize a) -> Heapsize b) -> Heapsize b # generalBracket :: HasCallStack => Heapsize a -> (a -> ExitCase b -> Heapsize c) -> (a -> Heapsize b) -> Heapsize (b, c) #
MonadThrow Heapsize # |
Instance details Defined in HeapSize Methods throwM :: (HasCallStack, Exception e) => e -> Heapsize a #
Applicative Heapsize # |
Instance details Defined in HeapSize Methods pure :: a -> Heapsize a # (<*>) :: Heapsize (a -> b) -> Heapsize a -> Heapsize b # liftA2 :: (a -> b -> c) -> Heapsize a -> Heapsize b -> Heapsize c # (*>) :: Heapsize a -> Heapsize b -> Heapsize b # (<*) :: Heapsize a -> Heapsize b -> Heapsize a #
Functor Heapsize # |
Instance details Defined in HeapSize Methods fmap :: (a -> b) -> Heapsize a -> Heapsize b # (<$) :: a -> Heapsize b -> Heapsize a #
Monad Heapsize # |
Instance details Defined in HeapSize Methods (>>=) :: Heapsize a -> (a -> Heapsize b) -> Heapsize b # (>>) :: Heapsize a -> Heapsize b -> Heapsize b # return :: a -> Heapsize a #

runHeapsize :: Int -> Heapsize a -> IO (Maybe a) #