[MLton-user] defunctorize limit?
Matthew Fluet
fluet at tti-c.org
Tue Dec 11 19:45:40 PST 2007
On Mon, 10 Dec 2007, Sean McLaughlin wrote:
> I'm experiencing some unexpected behavior. I have a number of
> functors parameterized by
> an abstract arithmetic signature. For most of my code, when these
> functors are instantiated to
> Real.real type, they run as fast as a version without the abstraction.
> However, I found an
> example that runs over 10X slower with the abstraction than without.
> That is, when I
> inline a monomorphic function at type real, it runs 10X faster than
> when I instantiate
> a functor with the exact same function body. So far I have been
> unable to construct
> a small example that exhibits this behavior. I was thus wondering if
> there is a limit
> to the amount of defunctorization being done. If so, perhaps there is
> a command line
> argument I could increase.
There is no limit to defunctorization; all functor bodies are
duplicated at every functor application site. I don't see anything
obvious from your code fragment that would explain the behavior you are
seeing. It should be the case that a functor application is equivalent to
copying the body of the functor to that point. Feel free to post code
demonstrating the behavior to:
http://mlton.org/TemporaryUpload
One thing that can happen when you manually duplicate code is that you
introduce identical functions that are inlined independently.
More information about the MLton-user
mailing list