[Paper Review] Interning Ground Terms in XSB
This paper presents an optimized implementation of ground term interning in the XSB tabled Prolog system, using hash-consing via tries to reduce space and time overhead in tabling. By interning ground terms—especially large lists—during tabled predicate execution, the approach cuts cputime from over 7 seconds to 0.265 seconds on a 500,000-element list lookup, while reducing redundant term copying and improving cache behavior.
This paper presents an implementation of interning of ground terms in the XSB Tabled Prolog system. This is related to the idea of hash-consing. I describe the concept of interning atoms and discuss the issues around interning ground structured terms, motivating why tabling Prolog systems may change the cost-benefit tradeoffs from those of traditional Prolog systems. I describe the details of the implementation of interning ground terms in the XSB Tabled Prolog System and show some of its performance properties. This implementation achieves the effects of that of Zhou and Have but is tuned for XSB's representations and is arguably simpler.
Motivation & Objective
- To reduce the time and space overhead of tabled Prolog execution caused by repeated copying of ground terms into and out of tables.
- To explore whether interning ground terms—beyond just atoms—can improve performance in tabled Prolog systems despite the cost of hashing.
- To design a simpler, more general, and orthogonal interning mechanism than prior work, particularly avoiding dependency on specific tabling implementations.
- To enable efficient representation sharing of ground terms in XSB by modifying term representation and unification to support interned references.
- To support future extensions such as garbage collection and selective interning of specific arguments to balance indexing and sharing.
Proposed method
- Interning ground terms using a trie-based hash table to store unique representations of ground terms, indexed by their structure and content.
- Modifying XSB’s term representation to interpret tagged pointers as references to interned terms, enabling constant-time equality checks via pointer comparison.
- Integrating interning into the tabled Prolog mechanism by automatically interning terms during tabled call and answer storage, especially for predicates like split_sorted/4 marked with the 'as intern' directive.
- Using a bottom-up term construction strategy with WAM-like instructions that check for internable subterms before building and interning new ground terms.
- Implementing a minimal change to the unification algorithm to handle interned term references, ensuring correctness while preserving performance.
- Supporting dynamic resizing of the intern table and planning for garbage collection of interned terms to manage memory growth.
Experimental results
Research questions
- RQ1Can interning ground terms in tabled Prolog systems reduce both time and space complexity compared to naive copying of subgoals and answers?
- RQ2How does interning ground terms affect caching behavior and locality of reference in tabled Prolog execution?
- RQ3What are the performance tradeoffs of interning ground terms in Prolog, especially given the high frequency of term creation in pure code?
- RQ4Can a simpler, more general interning mechanism be designed that is orthogonal to tabling and reusable across different Prolog systems?
- RQ5Under what conditions can interning be safely applied without compromising indexing or subsumption optimizations?
Key findings
- The implementation reduces cputime from over 7 seconds to 0.265 seconds on a 500,000-element list lookup, demonstrating a 26x performance improvement.
- The method uses only 111,464,680 bytes for interned terms and 466,608 bytes for table space, avoiding the quadratic overhead of repeated term copying.
- By interning terms during tabled predicate execution, the system avoids redundant construction and storage of identical ground terms such as large lists.
- The approach is simpler and more general than prior work by Zhou and Have, using tries instead of hash tables and avoiding complex memoization optimizations.
- The implementation supports future extensions such as garbage collection of interned terms and selective interning of specific arguments to preserve indexing.
- The method maintains correctness and efficiency by interning only ground terms and ensuring that pointer equality implies structural equality.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.