Bodigrim / tasty-bench

Featherlight benchmark framework, drop-in replacement for criterion and gauge.
https://hackage.haskell.org/package/tasty-bench
MIT License
80 stars 11 forks source link

How to avoid excessive GC #56

Closed wismill closed 5 months ago

wismill commented 5 months ago

So I have the following situation in unicode-data:

Lately I have experimented a hack that creates a pinned “list” using the foreign interface. This is ugly but seems to work, thanks to pinned memory being excluded from GC.

@Bodigrim What do you think? Is there a better way? Note that we would like to keep the dependencies as small as possible.

Bodigrim commented 5 months ago

@wismill maybe pack "interesting" Chars into a ByteArray instead of list?

wismill commented 5 months ago

You mean using e.g. newPinnedByteArray? But then I guess I can just reach for newPinnedByteArray# and further functions from GHC.Exts.

Anyway, you confirmed that pinned memory a good direction. Thanks for your insights. It may be worth noting it in the README.

Bodigrim commented 5 months ago

Not necessarily even pinned, copying continuous blocks of memory is extremely fast on modern processors. And any arrays over 3-4K are automatically pinned by RTS.