Opened 4 years ago

Last modified 4 years ago

#11226 new bug

Performance regression (involving sum, map, enumFromThenTo)

Reported by: j.waldmann Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.10.3
Keywords: Cc: nomeata
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

This program's performance suffers when compiled with 7.10, compared to 7.8:

main = print $ sum $ map bitcount [0, 4 .. 2^24-1 ]

bitcount :: Int -> Int
bitcount x =
  if x > 0 then let (d,m) = divMod x 2 in bitcount d + m else 0

See discussion in this thread: https://mail.haskell.org/pipermail/haskell-cafe/2015-December/122485.html

Change History (6)

comment:1 Changed 4 years ago by nomeata

Cc: nomeata added

No time to look deeply, but: Does the problem go away if the list is not statically known and thus prevented from floated out, e.g.:

main = print $ foo (2^24-1)

foo n = sum $ map bitcount [0, 4 .. n]
{-# NOINLINE foo #-}

bitcount :: Int -> Int
bitcount x =
  if x > 0 then let (d,m) = divMod x 2 in bitcount d + m else 0

comment:2 Changed 4 years ago by j.waldmann

Cc: nomeata removed

@nomeata: no, does not go away

comment:3 Changed 4 years ago by j.waldmann

I found that this works fine with 7.10:

main = print $ sum $ map bitcount $ takeWhile (< 2^24) [0, 4 .. ]

comment:4 Changed 4 years ago by nomeata

Cc: nomeata added

comment:6 Changed 4 years ago by thomie

Type of failure: None/UnknownRuntime performance bug
Note: See TracTickets for help on using tickets.