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

Bartlomiej Szymczak rhywek at gmail.com
Tue Jul 3 18:45:06 AEST 2007


On 7/3/07, Ralph Becket <rafe at csse.unimelb.edu.au> wrote:
> 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
> --------------------------------------------------------------------------
>

That's amazing. It will save me some work then. Thanks!
-- 
Bartlomiej Antoni Szymczak

Gmail: rhywek at gmail.com
Work mail: bas at imm.dtu.dk
Student mail: s041702 at student.dtu.dk
DTU office: 321/129
DTU tel.: +4545253892
Mobile: +4520789323
--------------------------------------------------------------------------
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