[MLton] Question on profile.fun
Matthew Fluet
fluet@cs.cornell.edu
Wed, 8 Jun 2005 14:42:37 -0400 (EDT)
> > > So, there is an insane shift after flatten and possibly a minor
> > > shift after contify3. I don't know if this actually lays the blame
> > > squarely at the feet of Flatten.flatten (or possibly
> > > Shrink.shrinkFunction).
> >
> > You could determine this by separating out the call to shrink from
> > flatten into a separate pass and then dropping profile labels in
> > between flattening and shrinking.
>
> Here are the results of that experiment:
>
> 1.97 dropProfileR
> flatten (* without shrinking *)
> 1.94 dropProfileFlatten
> shrink
> 12.94 dropProfileS
>
>
> > > Flatten.flatten doesn't appear to be sensitive to the presence of
> > > profiling statements in the program. But, there is something
> > > definitely going on there.
> >
> > Maybe. At least the shrinker does refer to profile annotations.
>
> Well, the above is encouraging, at least from the point of view that it
> confirms that flatten itself isn't really sensitive to the presence of
> profiling annotations.
Two things jumped out at me from looking at the pre/post shrink pass.
* We don't (and presumably can't) eliminate continuation eta-blocks that
have profile statements:
In the input program we have:
Enter Time.make <basis>/system/time.sml: 33
bigQuot_0 (global_17, global_16, tuple_5) NonTail {cont = L_1161,
handler = Handle L_902}
L_902 (x_1620)
Leave Time.make <basis>/system/time.sml: 33
L_903 (x_1620)
L_903 (x_1629)
L_906 (global_2, x_1629)
When profile statements are removed, then the shrinker simplifies the
above to:
bigQuot_0 (global_17, global_16, tuple_5) NonTail {cont = L_1161,
handler = Handle L_903}
L_903 (x_1629)
L_906 (global_2, x_1629)
With the profile statements, nothing changes.
But, I don't think there is anything to do in this case, as there isn't
anywhere to move the profile statement.
* The other situation is that we don't simplify Case blocks that
have profile statements.
In the input program we have:
Enter not <basis>/misc/basic.sml: 16
case x_1643 of
true => L_917 | false => L_909
L_909 ()
Leave not <basis>/misc/basic.sml: 16
L_910 (global_20)
L_911 ()
L_912 (global_119)
L_913 (x_1631)
x_1634 = (x_1631, x_1633)
x_1632 = ::_7 (x_1633, x_1631)
L_914 (x_1632)
L_914 (x_1635)
Leave List.mapPartial.fn <basis>/list/list.sml: 68
Leave List.foldl.loop <basis>/list/list.sml: 39
loop_76 (x_1635, x_1636)
L_915 ()
L_914 (x_1633)
L_912 (x_1637)
Leave List.filter.fn <basis>/list/list.sml: 73
case x_1637 of
NONE_4 => L_915 | SOME_3 => L_913
L_916 ()
x_1638 = SOME_3 (x_1639)
L_912 (x_1638)
L_910 (x_1640)
Leave StreamIOExtraFile.closeOut.fn <basis>/io/stream-io.fun: 890
case x_1640 of
true => L_916 | false => L_911
L_917 ()
Leave not <basis>/misc/basic.sml: 16
L_910 (global_43)
When profile statements are removed, then the shrinker simplifies the
above to:
case x_1643 of
true => L_917 | false => L_909
L_909 ()
x_1632 = ::_7 (x_1633, x_1641)
loop_76 (x_1632, x_1642)
L_917 ()
loop_76 (x_1633, x_1642)
With the profile statements, we only eliminate the assignment to x_1634:
Enter not <basis>/misc/basic.sml: 16
case x_1643 of
true => L_917 | false => L_909
L_909 ()
Leave not <basis>/misc/basic.sml: 16
L_910 (global_20)
L_917 ()
Leave not <basis>/misc/basic.sml: 16
L_910 (global_43)
L_910 (x_1640)
Leave StreamIOExtraFile.closeOut.fn <basis>/io/stream-io.fun: 890
case x_1640 of
true => L_916 | false => L_911
L_911 ()
L_912 (global_119)
L_916 ()
x_1638 = SOME_3 (x_1641)
L_912 (x_1638)
L_912 (x_1637)
Leave List.filter.fn <basis>/list/list.sml: 73
case x_1637 of
NONE_4 => L_915 | SOME_3 => L_913
L_913 (x_1631)
x_1632 = ::_7 (x_1633, x_1631)
L_914 (x_1632)
L_915 ()
L_914 (x_1633)
L_914 (x_1635)
Leave List.mapPartial.fn <basis>/list/list.sml: 68
Leave List.foldl.loop <basis>/list/list.sml: 39
loop_76 (x_1635, x_1642)
This seems much more significant. It also seems that it could be
accomodated by duplicating the profile statements when a trace through a
Case block is taken. We specifically rule this out by only simplifying
Case blocks where 0 = Vector.length statements.