[MLton-user] Tracking down allocations

Joe Hurd joe at gilith.com
Sat Jul 14 17:44:32 PDT 2007


Mainly as an intellectual exercise I've been trying to optimize a
piece of ML code as much as possible. In particular I'm using only
integers and integer arrays, plus a few datatypes of the form

datatype t = SingleConstructor of {a : int ref, b : int Array.array ref}

which I hope are free. It's still spending 4% of its time in garbage
collection, so I used

mlton -profile alloc -profile-branch true x.sml

to try to find where the allocations were being done, because I
thought I had eliminated them all. I got a confusing result that I
hope someone on this list can explain to me. I had a function of the
general form

fun f intArrayRef1 intArrayRef2 i =
  let
    fun g j k = ...big but non-recursive...

    val j = ...
    val k = ...
  in
    g j k
  end;

and the result of

mlprof -show-line true -raw true x mlmon.out

pointed me to the "let" line with 40,000,000,000 allocations being
done. Where exactly should I look next to see where the allocations
are being done?

Thanks for any help,

Joe



More information about the MLton-user mailing list