[mercury-users] Compiler optimization for large number of factual clauses.

Ralph Becket rafe at csse.unimelb.edu.au
Tue Jul 3 11:21:52 AEST 2007


Bartlomiej Szymczak, Friday, 29 June 2007:
> Hi.
> 
> Consider the following Mercury code:
> 
> :-type c --->
>        c_1;
>        c_2;
> ....(thousands of entries)
>        c_99999.
> 
> :-pred rel(c,c).
> :-mode rel(in,in) is semidet.
> :-mode rel(in,out) is nondet.
> :-mode rel(out,in) is nondet.
> 
> rel(c_1,c_2).
> rel(c_1,c_3).
> rel(c_3,c_1).
> ....(thousands of entries)
> rel(c_99999,c_3).
> 
> I want to ask how fast the "rel" predicate is. Will the compiler
> optimize it by adding some hash table based lookup? Are all three
> modes equivalently efficient? I need it to work as fast as possible,
> as "rel" is called very often in the remaining code.

The Mercury compiler goes to some lengths to compile switch based code
efficiently.  Your c type data constructors will be represented as integers
and some hash or tree scheme will be used to implement rel.

I've just run some quick tests and  performance appears
constant regardless of the number of constructors involved.

-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list