Ticket #7309 (new bug)

Opened 7 months ago

Last modified 5 weeks ago

The Ix instance for (,) leaks space in range

Reported by: nomeata Owned by:
Priority: normal Milestone: _|_
Component: libraries (other) Version: 7.6.1
Keywords: Cc: carter.schonwald@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

(at least if you take leak to mean unexpected space behaviour).

This was brought to my attention via  http://stackoverflow.com/questions/12780497/puzzling-memory-behavior-in-haskell where someone created a 6×10^6-array and was surprised that showing the array caused an additional (3+2)*8*10^6 bytes to be used. The reason (as far as I could tell) was this code:

instance (Ix a, Ix b) => Ix (a, b) where
    range ((l1,l2),(u1,u2)) = [ (i1,i2) | i1 <- range (l1,u1), i2 <- range (l2,u2) ]

in Arr.GHC. The result of range (l2,u2) is shared between every step in the first component of the index.

I guess it is reasonable to expect that the result of range is never worth sharing (is it?). I am not entirely sure what the best, cleanest, alternative implementation is, though. (At least not without a working dontshare annotation ;-))

Change History

Changed 7 months ago by simonpj

  • difficulty set to Unknown

Aha. See #7206, still on my stack, but would be delighted if someone took this on.

Changed 7 months ago by nomeata

Would #7206 really help here? After all, the problematic code is polymophic, so there is not a concrete range that could be inlined to a cheapBuild.

In code where the tuple-range is inlined and the concrete range functions of the element types are known (as in the second example in the stack exchange question), things already work out nicely as the foldr/builder fusion actually kicks in.

Changed 7 months ago by carter

  • cc carter.schonwald@… added

Changed 5 weeks ago by igloo

  • description modified (diff)

Changed 5 weeks ago by igloo

  • milestone set to _|_

Milestone _|_ to match #7206.

Note: See TracTickets for help on using tickets.