← ClaudeAtlas

prolog-performance-profilinglisted

Performance optimization and choicepoint profiling guidelines for Prolog. Use when eliminating unintended choice points, analyzing argument indexing, optimizing space complexity, and refactoring with library(reif).
dougransom/prolog-agent-toolkit · ★ 4 · API & Backend · score 60
Install: claude install-skill dougransom/prolog-agent-toolkit
# Prolog Performance & Choicepoint Profiling Guidelines Use this skill when auditing Prolog programs for memory usage, execution speed, tail recursion, indexing efficiency, and choicepoint leaks. ## 1. Choicepoint Elimination & Indexing Unintended choice points consume stack memory and degrade performance. - **First-Argument Indexing**: Most Prolog engines index on the principal functor of the **first argument**. Ensure the distinguishing input parameter is placed in the first position (`+Input, -Output`). ```prolog % GOOD: First argument indexing distinguishes empty list vs non-empty list process_list([], 0). process_list([X|Xs], Sum) :- ... ``` - **Clean Data Representations for Indexing**: Ensure terms are **clean** ([metalevel.at/prolog/data#clean](https://www.metalevel.at/prolog/data#clean)) by wrapping every data element kind in a distinct principal functor (e.g. `leaf(L)` vs `node(L, R)`). Defaulty representations prevent indexing and create open choicepoints. - **Reification over Cuts (`zcompare/3` & `if_/3`)**: Use `zcompare(Order, X, Y)` (from `library(clpz)`) for integer comparisons. It reifies the comparison into an atom (`<`, `=`, `>`) that matches directly in the first argument, avoiding choice points and cuts: ```prolog :- use_module(library(clpz)). :- use_module(library(reif)). % GOOD: Reified comparison produces an atom amenable to argument indexing max_pure(X, Y, Max) :- zcompare(Order, X, Y), max_order(Order, X, Y, Max). max_order(<, _, Y,