SWI-Prolog has nice JIT multi-argument indexing.
It might take some time before it kicks in. I just noticed
that my recent frontier/flooded solutions behaves different:
/* Cold Run, Higher Inference Count */
?- time(count(64,X)).
% 215,473 inferences, 0.031 CPU in 0.040 seconds (77% CPU, 6895136 Lips)
X = 3615.
/* Warm Run, lower Inference Count */
?- time(count(64,X)).
% 181,775 inferences, 0.016 CPU in 0.026 seconds (59% CPU, 11633600 Lips)
X = 3615.
The lower inference count has to do as soon as indexes are
present, the Prolog system can also perform choice point elimination?
Or some other JIT-ing artefact? Not 100% sure whats going on.
We should also not neglect the graden/3 facts, which need also a
JIT-ed indexe. I don’t know whether hashtable implementations can
compete with such implementations, since SWI-Prolog
does this all natively, right?
Edit 30.12.2023
Here you see the indexes it has created:
?- jiti_list(flooded/2).
Predicate Indexed Buckets Speedup Flags
============================================================================
user:flooded/2 1+2 4,096 4095.0
true.
?- jiti_list(frontier/2).
Predicate Indexed Buckets Speedup Flags
============================================================================
true.
it didn’t create an index for frontier/2 since frontier is called
with wild card query. On the other hand a crucial part of the
algorithm is to see whether something was already flooded,
the Just in Time indexing created a multi-argument index,
on argument 1 and then on argument 2. This could mean two
hashtable cascaded, which might better perform than one
hashtable, since computing a hash code of a pair is a science
in itself, with a lot of pitfalls. Basically the JIT multi-argument indexing
might be quite Datalog friendly. Whereas the single hashtable might choke.
Disclaimer: Could be wishful thinking, this is just some speculation.