Search code examples
prologbenchmarkingsicstus-prolog

SICStus Prolog: statistics/2 values affected by JIT


Update: As reported by @PerMildner, the below issue (present with SICStus Prolog 4.3.2) has vanished with the new SICStus Prolog 4.3.3! Way to go!


I'm using SICStus Prolog 4.3.2 and I'm getting to know some of the statistics/2 keys that I haven't used before... Here's my code:

:- use_module(library(lists)).

a_is_b_minus_c(A,B,C) :-
   A is B-C.

call_keys_deltas(Goal_0, Keys, Deltas) :-
   maplist(statistics, Keys, Values0),
   call(Goal_0),
   maplist(statistics, Keys, Values1),
   maplist(a_is_b_minus_c, Deltas, Values1, Values0).

call_keys_deltas/3 gathers some information about the execution of predicates like:

boolsA([]).                        
boolsA([0|Bs]) :- boolsA(Bs).
boolsA([1|Bs]) :- boolsA(Bs).

%%

bool(0).
bool(1).

boolsB([]).
boolsB([B|Bs]) :- bool(B), boolsB(Bs).

I'm expecting two choicepoints for ?- boolsA([0,0]).—but none for ?- boolsB([0,0]).

The numbers I get immediately after the JIT ran differ from the ones I get once it is done:

  • With JIT

    $ export SP_JIT=enabled && sicstus
    % ...
    | ?- call_keys_deltas(boolsA([0,0]), [choice_used,trail_used], Ds).
    Ds = [112,904] ? ;
    no
    | ?- call_keys_deltas(boolsA([0,0]), [choice_used,trail_used], Ds).
    Ds = [112,16] ? ;
    no
    | ?- call_keys_deltas(boolsB([0,0]), [choice_used,trail_used], Ds).
    Ds = [0,1264] ? ;
    no
    | ?- call_keys_deltas(boolsB([0,0]), [choice_used,trail_used], Ds).
    Ds = [0,8] ? ;
    no
    
  • Without JIT

    $ export SP_JIT=disabled && sicstus
    % ...
    | ?- call_keys_deltas(boolsA([0,0]), [choice_used,trail_used], Ds).
    Ds = [112,16] ? ;
    no
    | ?- call_keys_deltas(boolsA([0,0]), [choice_used,trail_used], Ds).
    Ds = [112,16] ? ;
    no
    | ?- call_keys_deltas(boolsB([0,0]), [choice_used,trail_used], Ds).
    Ds = [0,8] ? ;
    no
    | ?- call_keys_deltas(boolsB([0,0]), [choice_used,trail_used], Ds).
    Ds = [0,8] ? ;
    no
    

I wonder if above discrepancy is intentional... Thank for your help!


Solution

  • The difference was not intentional. It should be gone in the latest release of SICStus Prolog (4.3.3).

    Note that the choice_used did not differ, even before SICStus 4.3.3, and that statistic is probably what you should use in order to "quantify non-determinacy".