#1136: High memory use when compiling many let bindings.
------------------------------------------+---------------------------------
Reporter: igloo | Owner:
Type: compile-time performance bug | Status: new
Priority: high | Milestone: 6.8.3
Component: Compiler | Version: 6.6
Severity: normal | Resolution:
Keywords: performance | Difficulty: Unknown
Testcase: | Architecture: Unknown
Os: Unknown |
------------------------------------------+---------------------------------
Comment (by igloo):
For J2, consider this module:
{{{
module J where
data Foo a b c d = Foo a b c d
a = let
a0 = a3
a1 = a0
a2 = a1
a3 = a2
in Foo a0 a1 a2 a3
}}}
We get (tidied up a bit):
{{{
==================== Desugar ====================
Rec {
J.a :: forall t0 t1 t2 t3. J.Foo t0 t1 t2 t3
J.a = \ (@ t0) (@ t1) (@ t2) (@ t3) ->
letrec {
res :: J.Foo t0 t1 t2 t3
res =
letrec {
tup :: forall ttup. (ttup, ttup, ttup, ttup)
tup =
\ (@ ttup) ->
letrec {
tupa1 :: ttup
tupa1 = tupa0;
tupa2 :: ttup
tupa2 = tupa1;
tupa3 :: ttup
tupa3 = tupa2;
tupa0 :: ttup
tupa0 = tupa3; } in
(tupa0, tupa3, tupa2, tupa1);
a0 :: forall ttup. ttup
a0 = \ (@ ttup) -> case tup @ ttup of _ { (tup0, _, _, _) -> tup0
};
a3 :: forall ttup. ttup
a3 = \ (@ ttup) -> case tup @ ttup of _ { (_, tup1, _, _) -> tup1
};
a2 :: forall ttup. ttup
a2 = \ (@ ttup) -> case tup @ ttup of _ { (_, _, tup2, _) -> tup2
};
a1 :: forall ttup. ttup
a1 = \ (@ ttup) -> case tup @ ttup of _ { (_, _, _, tup3) -> tup3
};
} in
J.Foo
@ t0
@ t1
@ t2
@ t3
(a0 @ t0)
(a1 @ t1)
(a2 @ t2)
(a3 @ t3); } in
res
end Rec }
}}}
I think that most of the space usage comes from the tuple
deconstructors. We should look into desugaring into something like
this instead:
{{{
==================== Desugar ====================
Rec {
J.a :: forall t0 t1 t2 t3. J.Foo t0 t1 t2 t3
J.a = \ (@ t0) (@ t1) (@ t2) (@ t3) ->
letrec {
res :: J.Foo t0 t1 t2 t3
res =
letrec {
a0 :: forall ttup. ttup
a0 = \ (@ ttup) -> a3;
a3 :: forall ttup. ttup
a3 = \ (@ ttup) -> a2;
a2 :: forall ttup. ttup
a2 = \ (@ ttup) -> a1;
a1 :: forall ttup. ttup
a1 = \ (@ ttup) -> a0;
} in
J.Foo
@ t0
@ t1
@ t2
@ t3
(a0 @ t0)
(a1 @ t1)
(a2 @ t2)
(a3 @ t3); } in
res
end Rec }
}}}
Simon was worried about losing dictionary sharing if we did so, so we need
to check into whether that causes a performance problem, and whether we
can get the sharing some other way.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1136#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs