liveBook · Manning

parListChunk

As explained in Learn Haskell by Example

parListChunk is a parallel strategy combinator that evaluates list elements in chunks of a specified size.

parListChunk is a parallel Strategy for lists. It evaluates elements in chunks of a chosen size, creating fewer sparks than one-spark-per-element mapping. section 13.4.3

Use it when parallel list evaluation creates too much spark-management overhead:

  • Choose a chunk size so each spark performs enough work to justify its creation. section 13.4.3
  • Pair parListChunk with rseq; parListChunk already creates the parallel sparks, so rpar would add unnecessary work. section 13.4.3
  • Tune the size experimentally: excessive sparks can overflow the spark pool or slow execution through management and garbage-collection costs. section 13.4.3

Adapting a Vector

Because parListChunk operates only on lists, convert the Vector, apply the strategy, and convert back: fmap V.fromList . parListChunk size rseq . V.toList. An image-mapping function can use a chunk size such as ((w * h) `div` 1000), producing roughly 1,000 sparks. section 13.4.3

How Learn Haskell by Example covers it

How deep it goes
Explains chunking, rseq selection, Vector adaptation, and benchmarking, but leaves chunk-size choice to practical tuning.
Examples
Demonstrates chunked image mapping through a Vector adapter and a roughly 1,000-spark configuration.
What you can do after
Apply it via Control.Parallel.Strategies to reduce spark creation, adapt Vector workloads, and benchmark chunk-size choices.
How it connects
Connects parallel strategies with sparks, spark pools, rseq, vectors, and benchmarking.

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.