Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Optimizing false polymorphic local functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-02-14 (17:54)
From: Pascal Zimmer <Pascal.Zimmer@s...>
Subject: Re: [Caml-list] Optimizing false polymorphic local functions
Many thanks for the reference.
Just a last question: are there any reasons why this algorithm is not 
currently used in OCaml ? It does not seem very costly: as I was 
expecting, it is only a back-end to the classical typing algorithm, 
performing modifications on the type-annotated tree...

Pascal Zimmer

Xavier Leroy wrote:
>>The other day, I ran into a significant speedup improvement.
>>Now consider the slightly different version where "loop" is forced into
>>a monomorphic function:
>>On my computer in native code, the speedup is really significant: more
>>than 6 times faster (OK this example was built on purpose...). The
>>reason is that in the first case, the operator <= is replaced by a call
>>to the internal polymorphic compare_val function, whereas is the second
>>case a direct comparison between integers is performed.
>>I suspect there are other cases in which the compiler can produce a
>>better code when it knows more precisely the types involved. 
> Yes: besides comparisons, array and bigarray accesses can be compiled
> more efficiently if the exact types of the data are known statically.
>>So my question is: would it be possible to help him in this way by
>>enforcing the type checker to infer a monomorphic type in such
>>situations ? By "such situations", I mean: local polymorphic
>>functions that are used in exactly one monomorphic setting
>>afterwards. Of course, this is not desirable for global functions,
>>since it may break the calculus; but for local functions, it should
>>be of no harm since we know all the places where they are used, and
>>it would not change the type of the wrapper, thus being transparent
>>for the user...
>>Any comment ?
> The following paper formalizes exactly this idea, and gives a type
> inference algorithm that avoids unecessary polymorphism like you suggest:
> - Xavier Leroy
> -------------------
> To unsubscribe, mail Archives:
> Bug reports: FAQ:
> Beginner's list:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: