# Why doesn't ParallelMap improve the performance of FoldList?

This question arose during my analysis of the following problem: filling gaps. (The code used here is Simon Woods's work.)

FoldList seems to not cooperate with ParallelMap and I do not understand it:

f[_, y_] := y
f[x_, "."] := x

fill[data_] :=
Transpose[FoldList[f, First[#], Rest[#]] & /@ Transpose[data]]

fillP[data_] := Transpose[
ParallelMap[
FoldList[f, First[#], Rest[#]] &,
Transpose[data]]
]

data = Table[RandomChoice[{1, "."}], {10^6}, {4}]~Prepend~(Range@4);


Timings are as follows:

fill@data; // Timing // First (* -> 3.868825 *)
fillP@data; // Timing // First (* -> 4.056026 *)

-
Try mapping Length instead of FoldList[..]&, and maybe do a ByteCount on data. See what happens. –  Michael E2 Jun 10 '13 at 21:57
@MichaelE2 Map is faster then. I assume it is because of something like "preparing for parallelization". But for more complicated procedures than Lenght I expect faster ParallelMap option. It worked for some types of procedures (link). Or maybe I do not see what You are trying to tell me :) –  Kuba Jun 10 '13 at 22:13
What did you find for ByteCount@data? Almost 200MB? That has to be sent to each kernel. What happens to the timings of Length if the data is cut in half? Or to a tenth of its size? Is the time proportional to the size of data? Perhaps you will be able to answer your own question. ;D –  Michael E2 Jun 10 '13 at 22:29