[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Xavier Leroy <xavier.leroy@i...> |
| Subject: | Re: [Caml-list] Optimizing false polymorphic local functions |
> 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: http://citeseer.nj.nec.com/bjorner94minimal.html - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners