The cost of backtracking has been identified as one of the bottlenecks in
achieving peak performance in compiled Prolog programs. Much of the backtracking in
Prolog programs is shallow, i.e. is caused by unification failures in the head of a
clause when there are more alternatives for the same procedure, and so special treatment
of this form of backtracking has been proposed as a significant optimisation. This
paper describes a modified WAM which optimises shallow backtracking. Four different
implementation approaches are compared. A number of benchmark results are presented,
measuring the relative tradeoffs between compilation time, code size, and run time. The
results show that the speedup gained by this optimisation can be significant