caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <lists@philippewang.info>
To: Jim Grundy <jim_grundy@ichips.intel.com>, caml-list@inria.fr
Subject: Re: [Caml-list] A Question About Types and Inlining
Date: Sat, 09 Dec 2006 01:07:57 +0100	[thread overview]
Message-ID: <4579FE5D.1000002@philippewang.info> (raw)
In-Reply-To: <4579F8E1.6070604@ichips.intel.com>

Hi.

Ok I misread a line...

I saw once that there were a lot of optimizations based on types 
informations, especially on basic types... So hidding some type 
information would lead to prevent the compiler from some optimization...

Well, I wonder about how to hide the information from the users without 
hiding it to the type checker...

Typically the function compare (or other comparison operators) have to 
check the kinds of their arguments, except when the compiler knows that 
their types are basic types...

Well, I guess you use a lot the function compare ?

Have you tried to force the polymorphic functions' types that are only 
used with integers with the type int ?
(to take back the performance, you will have to tell explicitely the 
compiler to optimise them... or change the compiler code... I guess.)

Cheers,

   Philippe Wang.

Jim Grundy a écrit :
> Hi Philippe
> 
> Thanks for the mail.  That's not quite what I'm looking for:
> 
> I have some module Foo, that implements a type, lets call it abs, that I 
> would like to keep abstract as far as the other modules are concerned.
> 
> In foo.mli I have
> 
>   type abs
> 
> and in foo.ml I have
> 
>   type abs = int
> 
> (which is the set up you were recommending, right)
> 
> But... if I change foo.mli to reveal the type to other modules, that is 
> if foo.mli also says
> 
>   type abs = int
> 
> then the program runs 36% faster.
> 
> I suspect that hiding the type is either preventing inlining of calls 
> from other modules to functions in the foo module, or that hiding the 
> type is forcing the other modules to use a boxed representation rather 
> than an unboxed representation.
> 
> All the best
> 
> Jim
> 
> Philippe Wang wrote:
>> Hi.
>>
>> If I have understood what you meant :
>>
>> Create a .mli file where you put
>> type variable
>>
>> and in the .ml file, put
>> type variable = int
>>
>>
>> It should do what you want (i.e. tell the compiler that the actual 
>> type is int and not allow unifying int type with variable type elsewhere)
>>
>> Note : ocamlopt -i yourmlfile.ml prints the default .mli
>> So you can generate the default .mli easily (at least on unix or cygwin)
>>
>> Cheers,
>> Philippe Wang
>>   mail@philippewang.info
>>
>>
>>
>> Jim Grundy a écrit :
>>> Apologies in advance for a naive question...
>>>
>>> I'm working on a SAT solver in OCaml.  The solver has various types, 
>>> like three-valued bools, variables, literals.  I have modules that 
>>> encapsulate these types and the operations on them.
>>>
>>> Now, as it turns out, all these types are represented as ints, but 
>>> the other modules that use those types don't need to know that - and 
>>> as a matter of taste I'd rather not expose this.
>>>
>>> The signatures of these modules currently contain lines like this:
>>>
>>> type variable (* = int *)
>>>
>>> If I uncomment all instances of (* = int *) and reveal the 
>>> representation to the compiler then I get a ... 36% performance 
>>> improvement in the SAT solver.
>>>
>>> I have two questions:
>>>
>>> 1/ Is there some way I can reveal this representation to the parts of 
>>> the system that clearly need it for effective optimization, without 
>>> opening this up for general use.
>>>
>>> 2/ Failing that, has someone got a pleasant method of doing 
>>> conditional compilation so that I can switch these comments on and 
>>> off with ease?
>>>
>>> I'm using version 3.09.2 of ocamlopt.
>>>
>>> Thanks in advance
>>>
>>> Jim
>>>
>>>
> 


  parent reply	other threads:[~2006-12-09  0:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-08 23:13 Jim Grundy
     [not found] ` <4579F655.3030307@philippewang.info>
     [not found]   ` <4579F8E1.6070604@ichips.intel.com>
2006-12-09  0:07     ` Philippe Wang [this message]
2006-12-09  0:55 ` [Caml-list] " Eric Cooper
2006-12-09  1:16   ` Philippe Wang
2006-12-09  1:31     ` Eric Cooper
2006-12-09  9:28   ` Jon Harrop
2006-12-09 11:28 ` Andrej Bauer
2006-12-09 13:12 ` Nicolas Pouillard
2006-12-10  6:27 ` Christian Stork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4579FE5D.1000002@philippewang.info \
    --to=lists@philippewang.info \
    --cc=caml-list@inria.fr \
    --cc=jim_grundy@ichips.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).