Fast Dynamic Predicates
Dynamic predicates (see dynamic, asserta, assertz, retract) are now
implemented with smart indexing.
Customer applications which make heavy use of dynamic
predicates showed a performance increase of two orders of magnitude
over previous versions of MINERVA.
A word about indexing in MINERVA: indexing is a general word for
a variety of methods to increase access speed to collections of
data from linear resp exponential to constant resp logarithmic time.
In MINERVA there are 3 forms of data: compiled predicates,
dynamic predicates, and blackboards.
For compiled predicates, "first argument indexing" is used for
collections of predicates where the first argument is not a
variable. Indexing works on the functor and arity of the predicate
and the functor of the first argument,
deeper parts of a term are not used.
For dynamic predicates, "smart indexing" is done whenever MINERVA
considers it worthwhile over all arguments which are never asserted
as a variable. Indexing works on the functor and arity of the predicate
and the functor of the targeted arguments, deeper parts of a term are not used.
For data stored in blackboards, "exhaustive indexing" is done over
the key: the whole term, incuding its deeper parts, is used as
material for indexing.
Programming Hints:
1) Indexing can only be performed for data sets that are "ground"
i.e. not variables in the important locations. Indexing something
like:
a(1).
a(2).
a(X) :- X = undetermined. % catch-all case
will NOT result in the desired speedup. This is a BAD example.
2) Access to indexed data sets is only fast if the key is actually
used. Compare:
Data:
male(eric).
male(kentaro).
:
female(mika).
female(sonya).
:
Program:
% GOOD % BAD
?- male(charles). ?- male(X), X = kaori.