[GHC] #7309: The Ix instance for (,) leaks space in range
GHC
cvs-ghc at haskell.org
Fri Apr 12 17:02:01 CEST 2013
#7309: The Ix instance for (,) leaks space in range
----------------------------------+-----------------------------------------
Reporter: nomeata | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: libraries (other) | Version: 7.6.1
Keywords: | Os: Unknown/Multiple
Architecture: Unknown/Multiple | Failure: Runtime performance bug
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
----------------------------------+-----------------------------------------
Description changed by igloo:
Old description:
> (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 ;-))
New description:
(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 ;-))
--
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7309#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list