[MLton-devel] Porting from Moscow ML

Stephen Weeks MLton@mlton.org
Sat, 28 Sep 2002 17:50:28 -0700


> In fact, the main reason for porting to MLton was to make use of the
> profiling facilities, but I was rather disappointed with the results:
> I hardly recognized any of the functions in my program in the
> yellow/red areas of the call graph.

I tried out mlprof on your program as follows:

% mlton -keep dot -profile true z.sml
% ./z >/dev/null
% mlprof -t 1 -color -s z mlmon.out
53.75 seconds of CPU time
f_0                        26.33%
forward (C @ 0x80CC300)     7.81%
<unknown>                   7.35%
x_5914                      5.00%
isAligned (C @ 0x80C7260)   4.84%
x_5219                      4.45%
ins_0                       3.89%
cheneyCopy (C @ 0x80C8380)  3.72%
equal_list_1                3.11%
x_9474                      3.01%
x_5028                      2.66%
String_equal (C)            2.60%
TP_0                        2.16%
x_9447                      2.01%
x_6644                      1.56%
x_4430                      1.40%
x_8678                      1.32%

All the (C @ 0x???) stuff is GC.  The top most used function is f_0.
To figure out what that is, have a look at the SSA code for fun f_0 in
z.ssa and at the SSA control-flow graph for f_0.

% /usr/bin/dot -Tps z.f_0.cfg.dot >f_0.ps
% gv f_0.ps &

Looking at that, I see that the first thing f_0 does is a case on its
only argument to see whether it is variant Fn or variant Var.  Looking
through your source code, there is only one such f function, in
tm_subst.  Looking further in the control-flow graph, you can see that
find_unchanged and list_unchanged have been inlined inside f.  You can
also try the -d 1 option to mlprof to see the hot basic blocks inside
f_0.  Again, with -color it will color the SSA control-flow graph.

Anyways, I hope that gives you the idea.  I'm afraid that's the best
we have for now -- look at the SSA code and the corresponding
control-flow graph, and look for the matching code in the SML source.

All of the x_???? functions are anonymous lambdas in the source.
These often arise from curried functions.  For example, x_5914 appears
to be tree_foldr (which is curried).  In particular it appears to be
the use in TermNet1.to_list.  I see lots of flattens and maps there.
Those can often be deforested and optimized.

Hope this helps.  Please feel free to ask questions about the SSA
IL and dot graphs, since those aren't too well documented.

Good luck.


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel