Slow clause indexing

From: Sebastian Brand <Sebastian.Brand_at_cwi.nl>
Date: Mon 04 Feb 2002 04:24:26 PM GMT
Message-ID: <20020204172426.A1483@cwi.nl>
Hello,

this is not a bug, but rather an Eclipse implementation question,
therefore I'm sending it here; hoping for some hints.  I am faced
with the task of calling a set of clauses in the following fashion:


	iterate_start(DataIn, DataOut) :-
		PList = [1,2, ... n],		%%  n is known
		p(PList, DataIn, DataOut).


	:- mode p(++, ...).

	p([1 | PList], DataIn, DataOut) :- !,
		update1(PList, PListNext),
		...
		p(PListNext, DataNext, DataOut).

	p([2 | PList], DataIn, DataOut) :- !,
		update2(PList, PListNext),
		...
		p(PListNext, DataNext, DataOut).

	...

	p([], Data, Data).


The updates on PList can be increasing or decreasing, but termination
is guaranteed.  Plist can be long: n can be in the 1000s (the clauses
are generated).  The above way relies on indexing.  Another is to
construct the clause calls:


	p([Pname | PList], DataIn, DataOut) :-
		Pcall =.. [Pname, DataIn, DataOut],
		call(Pcall).

	p([], Data, Data).



	p1(PList, DataIn, DataOut) :-
		update1(PList, PListNext),
		...
		p(PListNext, DataNext, DataOut).

	p2(PList), DataIn, DataOut) :-
		update2(PList, PListNext),
		...
		p(PListNext, DataNext, DataOut).


This is *a lot* faster (a factor > 10) than the indexing-approach
in one experiment I did (with n=4000).  However, to rely on
indexing is certainly more elegant, and would allow faster update
functions of Plist.  Profiling also shows that pnext and =.. are
somewhat costly.

My questions:  Is this behaviour to be expected?  Are there
improvements I could try?


Thanks for your time,
Best Regards,
Sebastian Brand
Received on Mon Feb 04 16:24:28 2002

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:08:13 PM GMT GMT