[MLton] Profile driven packing...
Daniel C. Wang
danwang@CS.Princeton.EDU
Tue, 27 Apr 2004 15:29:04 -0400
Given that MLton now has lots of cool bit-packing opts built in, I just
wanted to mention one of my pet optimizations that I always wanted to add
but never found the time too do
Consider a simple datatype
datatype t = T of Word32.word * Word32.word
Lets say you run a space profiler or via some domain knowledge happen to
know that most of the time you are just storing small words...
one could "optimize" the above to
datatype t = T1 of Word16.word * Word15.word
| T2 of Word32.word * Word32.word
the basic idea is to use profile driven represenations of datatypes to get
better space utilization and possibly better cache locality.
The real trick is to make this all transparent to the programmer so they
don't know what's going on behind the scenes...
I was going to do this once in SML/NJ but there were so many things that got
in the way.. I suspect MLton has almost all the infrastructure to do this
sort of thing.. except for the very detailed heap-profiler.....
Anyway, just food for thought..
BTW just as a user feed back level.. is there some way of asserting that a
particular ML type will be laided out/packed in a certain way?
I'd be happy to see a pragma/comment
So that I can can say something like
datatype t = A of Int31.int | B of Int31.int (*:packed: unboxed 32*)
and have the compiler complain when my expectation is not meet?