Haskell pauses (seemingly) randomly while generating Fibonacci Numbers

Viewed 123

I was playing with GHCI, and came across this little (to me) oddity.

I tried this:

λ> let fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
λ> fibs

Just to see how quick fibs grow and just to play around a bit. I think it's cool how Haskell displays each fib as it is calculated, so it's a nice demonstration of laziness.

However, as I saw the wall of numbers zoom by, there were momentary skips where the list generation would completely stop. Normally I would just think that it was computing the next number, but they seemed to happen randomly - and calculating the next fib number is always just one addition, so should never be slow. On one number, ghci paused for almost a second.

What's causing these momentary slowdowns? Why would they happen only on specific numbers and not others? Shouldn't this always be fast?

2 Answers
Related