[MLton-user] Profiling as a compiler optimization boost.

Raymond Racine rracine@adelphia.net
Fri, 29 Oct 2004 22:33:03 -0400


I am at a very rare moment of partial stability with my Rete code and
decided to do a couple of large tests and grab a profile measurement or
two.  Just curious as I've a ways to go before I start optimizing.

The test is assert 100,000 production rules.  Two conjunctive conditions
per rule.  Add 100,000 facts and 100,000 new facts are asserted into the
Working Memory of the Rete.  So 100K rules, 100K base facts, 100K
inferred facts.

The first time is for adding the production rules.
i.e. {?x :color :blue} {?x :shape :round} => ASSERT {:little_boy :play
?x} {?x :isa :ball}

The second time is to add and fire a fact.
{ :ball_1 :color :blue}
{ :ball_1 :shape :round}
....

================================================================
[ray@aragon rete]$ mlton rete.mlb
[ray@aragon rete]$ time ./rete @MLton ram-slop 0.7 --
Done: 1.362
Done: 1.882
                                                                                                                             
real    0m3.541s
user    0m2.810s
sys     0m0.720s
[ray@aragon rete]$ mlton -profile time rete.mlb
[ray@aragon rete]$ time ./rete @MLton ram-slop 0.7 --
Done: 1.502
Done: 0.736
                                                                                                                             
real    0m2.265s
user    0m1.810s
sys     0m0.460s
[ray@aragon rete]$
========================================================

Note the very nice performance boost WITH PROFILING ENABLED????
Rather unexpected.  Tough week and I'm zapped so I haven't dug around
yet though I suspect that allocation profiling will be interesting.

BTW the top of the mlprof is...
                    function                      cur
------------------------------------------------ -----
<gc>                                             32.1%
Sequence.append                                  19.6%
Integer.fmt.loop                                  8.9%
Sequence.tabulate                                 6.7%
HashTableFn.find.look                             4.0%
ReteNode.mkTokenVariant                           2.2%
BaseRete.matchOneWME.extract                      1.8%
BigRete.addProd                                   1.8%
Log.log                                           1.3%
ReteNode.tokenNthFrom                             1.3%
ReteNode.mkJoinNode                               1.3%
JoinNodeTest.mkJoinTestsForCondition              1.3%
DList.foreach.apply                               1.3%
HashString.hashChar                               0.9%
AlphaNetworkFn.AMKey.sameKey                      0.9%
BaseRete.joinNodeRightActivation                  0.9%


Ray