Date: Fri, 22 Oct 1999 11:42:50 +0200
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: John Prevost <prevost@maya.com>
Subject: Re: 32 bit integers
In-Reply-To: <m33dv4tgc3.fsf@isil.maya.com>; from John Prevost on Thu, Oct 21, 1999 at 08:00:12PM -0400
> I found this implementation to be terribly slow (even slower than the
> bignum stuff in many cases.) Any idea why this is? Is it just
> because of the extra dereference, or is it because the compiler uses
> better code for "primitive" type operations like int addition than it
> does for other types?
Both, actually. Boxing is always expensive, not so much because of
the extra dereference, but mostly because of the extra heap allocations.
(There are good reasons why the "int" type is tagged instead of boxed
in OCaml...) On top of that, all operations on Int32.t are
implemented by C functions, and calling a C function from Caml is
expensive -- more expensive than calling a Caml function, and much
more expensive than open-coding the operations.
> (This second was my guess.) Is there any way
> to make this kind of extension work better?
There is a way, but it involves modifying the compiler itself
to add special code generation rules for the primitive operations on
the new integer type.
- Xavier Leroy
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:27 MET