remove optional (+)/1 prefix in get_atts/2 and put_atts/2 calls

The (+)/1 prefix in get_atts/2 at line 4219 by itself already causes a
greater than 15% slowdown for the benchmark shown in #1730:

    ?- N #= 2^14,
       time(((between(1, N, _),
              X #\= Y,
              false)
            ; true)).

The performance impact is not a good reason to remove the optional
(+)/1 prefix! Performance issues should be addressed at the root, in
this case get_atts/2 (#1962). We should never manually work around
performance issues in built-in predicates.

In contrast, readability is a good argument, and I find the calls
slightly easier to read without the optional (+)/1 prefix.

The prefix is now consistently omitted when possible.
This commit is contained in:
Markus Triska
2023-08-20 21:38:33 +02:00
parent 7f024f3b8d
commit 24456e9703

View File

@@ -3967,7 +3967,7 @@ insert_queue(Element, Which) -->
Tail0 = [Element|Tail]
; Head = [Element|Tail]
),
put_atts(Arg, +queue(Head,Tail)) }.
put_atts(Arg, queue(Head,Tail)) }.
domain_spread(Dom, Spread) :-
@@ -4199,9 +4199,9 @@ ignore(Goal) :- ( Goal -> true ; true ).
print_queue -->
state(queue(Goal,Fast,Slow,_)),
{ ignore(get_atts(Goal, +queue(GHs,_))),
ignore(get_atts(Fast, +queue(FHs,_))),
ignore(get_atts(Slow, +queue(SHs,_))),
{ ignore(get_atts(Goal, queue(GHs,_))),
ignore(get_atts(Fast, queue(FHs,_))),
ignore(get_atts(Slow, queue(SHs,_))),
format("Current queue:~n goal: ~q~n fast: ~q~n slow: ~q~n~n", [GHs,FHs,SHs]) }.
@@ -4216,14 +4216,14 @@ queue_get_arg(Which, Element) -->
queue_get_arg_(Queue, Which, Element) :-
arg(Which, Queue, Arg),
get_atts(Arg, +queue([Element|Elements],Tail)),
get_atts(Arg, queue([Element|Elements],Tail)),
( var(Elements) ->
put_atts(Arg, -queue(_,_))
; put_atts(Arg, +queue(Elements,Tail))
; put_atts(Arg, queue(Elements,Tail))
).
queue_enabled --> state(queue(_,_,_,Aux)), { \+ get_atts(Aux, disabled) }.
disable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, +disabled) }.
disable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, disabled) }.
enable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, -disabled) }.
portray_propagator(propagator(P,_), F) :- functor(P, F, _).