On Combining Linear-Based Strategies for Tabled Evaluation of Logic Programs
Tabled evaluation is a recognized and powerful technique that overcomes some limitations of traditional Prolog systems in dealing with recursion and redundant sub-computations. We can distinguish two main categories of tabling mechanisms: suspension-based tabling and linear tabling. While suspension-based mechanisms are considered to obtain better results in general, they have more memory space requirements and are more complex and harder to implement than linear tabling mechanisms. Arguably, the SLDT and DRA strategies are the two most successful extensions to standard linear tabled evaluation. In this work, we propose a new strategy, named DRS, and we present a framework, on top of the Yap system, that supports the combination of all these three strategies. Our implementation shares the underlying execution environment and most of the data structures used to implement tabling in Yap. We thus argue that all these common features allows us to make a first and fair comparison between these different linear tabling strategies and, therefore, better understand the advantages and weaknesses of each, when used solely or combined with the others.
💡 Research Summary
The paper addresses the performance limitations of traditional Prolog’s SLD resolution when dealing with recursion and redundant sub‑computations by focusing on tabling, a technique that stores intermediate solutions for subgoals and reuses them on repeated calls. Two major categories of tabling mechanisms exist: suspension‑based tabling, which preserves the execution state of suspended subgoals, and linear tabling, which iteratively recomputes subgoals until a fix‑point is reached. While suspension‑based approaches generally achieve better raw performance, they consume more memory and are harder to implement. Linear tabling, on the other hand, is simpler and more memory‑efficient but suffers from the need to re‑explore the entire search space of a strongly connected component (SCC) after each new solution is found.
Within the linear family, two successful optimizations have been proposed previously: SLDT (also called DRE – Dynamic Reordering of Execution) and DRA (Dynamic Reordering of Alternatives). DRE distinguishes a “pioneer” call (the first encounter of a tabled subgoal) from “follower” calls (subsequent encounters). When backtracking to a pioneer or follower, the strategy first explores any remaining program clauses before consuming answers, thereby giving priority to clause execution and reducing unnecessary answer consumption. DRA, conversely, records the clauses that lead to consumer calls (the “looping alternatives”). In subsequent re‑evaluations of an SCC, only these looping alternatives are tried, avoiding the full clause set and thus cutting down the amount of work per iteration.
The authors introduce a third strategy, Dynamic Reordering of Solutions (DRS), which can be seen as a counterpart to DRA applied to answer consumption rather than clause selection. When a non‑leader generator consumes a solution that triggers a consumer call, that solution is memorized as a “looping solution”. In later re‑evaluations, the generator re‑consumes only the newly produced solutions together with the stored looping solutions, skipping all other answers that would only be repeated. This reduces the overhead associated with repeatedly propagating the same answers across SCC iterations.
All three strategies—DRE, DRA, and the newly proposed DRS—are integrated into the YAP Prolog system. The implementation leverages YAP’s existing trie‑based table space, adding only modest metadata (flags for call type, lists of looping alternatives, and lists of looping solutions). Because the core execution engine and data structures remain unchanged, the memory footprint stays comparable to the baseline linear tabling system.
Experimental evaluation uses a suite of benchmarks that include mutually recursive predicates, graph reachability, and non‑recursive fact retrieval. The authors compare six configurations: (1) plain linear tabling, (2) DRE only, (3) DRA only, (4) DRS only, (5) DRE + DRA, and (6) DRE + DRA + DRS. Results show that each individual optimization reduces the number of SCC re‑evaluations and the total number of clause executions. DRA is especially effective at cutting down clause re‑execution, while DRS yields the most benefit when many solutions are repeatedly consumed. The combination of DRA and DRS (configuration 6) consistently achieves the lowest execution times, often halving the runtime compared with plain linear tabling, with only a slight increase in memory usage due to the extra bookkeeping.
The analysis highlights that the three strategies are largely orthogonal: DRE improves the order of clause exploration, DRA prunes the set of clauses to be revisited, and DRS prunes the set of answers to be re‑propagated. Consequently, their combined use provides a synergistic effect that addresses both dimensions of redundancy—unnecessary clause traversal and unnecessary answer consumption. The paper concludes that integrating these linear‑tabling optimizations into a single system not only enables fair empirical comparison but also offers a practical, high‑performance solution for real‑world logic programs that exhibit complex recursion patterns. Future work is suggested in the direction of automatic strategy selection based on program characteristics and extending the approach to handle more intricate SCC structures.
Comments & Academic Discussion
Loading comments...
Leave a Comment