From time to time I use the profiler to get a big picture view of where my code is spending time. The port count data can be sometimes difficult to interpret; here’s a simple example:
p(N) :- N mod 2 =:= 1 -> g1 ; g2. g1. g2.
Given the semantics of “If-Then;Else”,
p/1 is determinstic so I would expect
p’s Call and Exit port counts to be 1000, and Redo and Fail port counts to be 0 (with
g2 each called half the time).
However the profiler data shows Redo and Fail port counts of 500. It looks like the Redo/Fails from “If-Then;Else” (not actually a predicate itself since the compiler optimizes it away) get accumulated up to the parent predicate.
I find this mildly confusing with this simple example, but when you have legitimate non-deterministic predicates (multiple clauses leaving choicepoints), making sense of the counts gets quite difficult.
Is there some way of discarding or separating out the port counts due to “If-Then;Else” from the parent predicate? Are there any other similar cases where apparent miscounting occurs?