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 slow?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: slow?
> I used as a comparison function between hash values
> (16-byte strings). is a polymorphic hack that works by
> induction on the type information left for the garbage collector; even if
> you specify : string -> string -> int, it still invokes
> the polymorphic function.
> There is apparently a 20-25% performance penalty using this form instead
> of a simple comparison procedure for 16-byte strings. I suspect the
> performance hit is even higher for more complex data structures.
> Would it be possible to have ad hoc generated comparison functions? That
> sounds like it needs including polytypic features into the language, which
> is some very big stuff.

Actually, there is some "polytypic" optimisations going on in the
compiler.  For instance, the compiler will replace the generic "="
function by integer equality if both arguments are known to be of type

Such "type-based strength reduction", as I like to call it, is
currently applied to all boolean comparisons (=, <>, <, <=, >, >=) but
not to "compare".  It could be done for "compare" as well; it's just
that no one has yet expressed a strong need for this...

- Xavier Leroy