Call overhead goal_family(pref, Arg) vs. goal_family_pref(Arg)

Hello,

I have a goal family that can be specified as either with a prefix to distinguish between goals, or parameterized, say, with a first argument, to distinguish processing.

The first would be “compile time” linking between caller and called goal, whereas the other involves a lookup by first argument.

Is there a difference in how in each case the goal selection occurs and or are both equivalent, call performance wise.

thank you,

Dan

goal_family_pref(Arg) surely wins as it has to push only one argument and the possibly required clause indexing is simpler. But … if the more specific goal forces you to less efficient code elsewhere, e.g., a test to see which predicate to call, you might overall loose. Timing and profiling give answers, although these are not set in stone due to future changes in SWI-Prolog, the C compiler and even the hardware.

Thank you.

As it currently stands, the main drawback of goal_family_pref, is that it forces repetitive code blocks / predicates higher up architectural stack – and most of it can be eliminated through the parameterized version with a first Arg passed down the stack until its leads to a decision at the lowest level.

There is, currently, a bit of test code that must happen as well, which also destroys conceptual integrity a bit – i.e. knowledge at a lower level bubbles up.

I am currently opting for the parameterized version – but, might, then, need to revisit this if the overhead profiles as significant.

thank you,

Dan