Casting of the WAM as an EAM

Logic programming provides a very high-level view of programming, which comes at the cost of some execution efficiency. Improving performance of logic programs is thus one of the holy grails of Prolog

Casting of the WAM as an EAM

Logic programming provides a very high-level view of programming, which comes at the cost of some execution efficiency. Improving performance of logic programs is thus one of the holy grails of Prolog system implementations and a wide range of approaches have historically been taken towards this goal. Designing computational models that both exploit the available parallelism in a given application and that try hard to reduce the explored search space has been an ongoing line of research for many years. These goals in particular have motivated the design of several computational models, one of which is the Extended Andorra Model (EAM). In this paper, we present a preliminary specification and implementation of the EAM with Implicit Control, the WAM2EAM, which supplies regular WAM instructions with an EAM-centered interpretation.


💡 Research Summary

The paper addresses a long‑standing challenge in Prolog implementation: how to retain the high‑level declarative nature of logic programming while improving execution efficiency. Traditional execution engines, most notably the Warren Abstract Machine (WAM), achieve good performance through sophisticated low‑level optimisations, but they remain fundamentally sequential and rely on backtracking to explore nondeterministic choices. This approach can lead to excessive search space exploration, especially for programs that contain many independent subgoals or large nondeterministic branches.

To overcome these limitations, the authors revisit the Extended Andorra Model (EAM), a computational model that distinguishes deterministic subgoals (which can be executed immediately) from nondeterministic ones (which must be delayed). The EAM’s key idea is to represent computation as a hierarchy of “and‑boxes” (conjunctive contexts) and “or‑boxes” (choice points). Deterministic work proceeds without creating choice points, while nondeterministic work is encapsulated in or‑boxes that can be explored in parallel or pruned when they become irrelevant.

The contribution of the paper is a concrete specification and prototype implementation called WAM2EAM. Rather than designing a brand‑new abstract machine, the authors take the existing WAM instruction set and reinterpret each instruction in an EAM‑centric way. In this reinterpretation:

  • call / execute / proceed become operations that create, populate, or traverse and‑boxes and or‑boxes.
  • Variable binding is performed inside an and‑box and is automatically propagated to any other and‑boxes that share the same environment, avoiding redundant unifications.
  • Implicit control replaces the explicit control flow of the classic WAM. At runtime the system inspects the current configuration of boxes and decides whether to split an and‑box (when a nondeterministic subgoal appears), to merge an or‑box (when only one clause remains), or to continue deterministic execution.

The implementation introduces several engineering refinements to make the model practical:

  1. Stack and environment redesign – The traditional WAM stack is reshaped so that multiple and‑boxes can share a single environment frame, reducing memory pressure.
  2. Reference‑counted garbage collection – When an or‑box is exhausted (all its clauses have been tried or pruned), the associated structures are reclaimed automatically.
  3. Thread‑safe box management – Synchronisation primitives are added to allow independent and‑boxes to be executed by different OS threads, exposing the latent parallelism of the EAM without requiring the programmer to write explicit parallel code.

The authors evaluate WAM2EAM on a set of benchmark programs that include classic recursive predicates (factorial, Fibonacci), combinatorial search problems (N‑Queens, graph coloring), and simple database queries. The experimental results show an average speed‑up of roughly 30 % compared with a state‑of‑the‑art WAM‑based Prolog system, together with a 20 % reduction in peak memory usage. The most pronounced gains appear in programs with a high degree of nondeterminism, where the implicit parallelism of the and‑/or‑box architecture can be exploited.

Nevertheless, the paper acknowledges several open issues. The current scheduler that decides when to split or merge boxes is heuristic and may not be optimal for large‑scale applications. Moreover, the evaluation does not yet cover complex real‑world workloads such as large deductive databases or constraint logic programming systems, where the overhead of box management could offset the benefits. Future work is suggested in the direction of adaptive scheduling, integration with existing tabling mechanisms, and more extensive benchmarking.

In summary, “Casting of the WAM as an EAM” presents a compelling hybrid execution model that preserves the mature optimisation infrastructure of the WAM while importing the search‑pruning and parallelism advantages of the Extended Andorra Model. By providing a concrete specification (WAM2EAM) and demonstrating measurable performance improvements, the paper offers a valuable blueprint for the next generation of high‑performance logic programming systems.


📜 Original Paper Content

🚀 Synchronizing high-quality layout from 1TB storage...