HELP EFFICIENCY Chris Mellish Sept 1982 Revised by Kathryn Seifert August 1986 Hints about how to make Prolog programs more efficient Keywords: efficiency, system, compilation -- EFFICIENCY IN PROLOG ---------------------------------------------- If you are very worried about the efficiency of your Prolog programs, the following hints may be useful: 1) COMPILE A WHOLE PROCEDURE IN ONE GO If the Prolog system reads all the clauses for some predicate as a contiguous chunk in a file (or from the terminal), it can make a significantly faster procedure from them than if it reads them interspersed with other clauses, or if clauses are added and deleted to them by use of 'assert' and 'retract'. 2) USE CUTS The use of a cut where a procedure is determinate reduces the amount of space occupied by the running program (and hence garbage collection time). It also reduces the time spent by the system trying possibilities that cannot possibly succeed. 3) ALLOCATE DISCRIMINATORY ARGUMENTS TO THE FRONT When Prolog matches a goal against the head of a clause, it attempts to match the arguments from left to right. So if the choice of a which clause is appropriate depends mainly on some particular argument, it makes sense to make that the first argument. 4) MAKE USE OF POP PROCEDURES There may be a POP-11 procedure to do just what you want, either in the POP-11 system, or in the POP-11 library. If so, it may be faster than the corresponding Prolog procedure. See PLOGHELP * PLOGTOPOP and PLOGHELP * MIXED_LANGUAGES for how to call POP-11 procedures from Prolog. If you use PROLOG_EVAL (see PLOGHELP * PROLOG_EVAL in the first goal of a clause (or the first goal after a cut), the result is almost as fast as calling the relevant POP-11 procedures directly from POP-11. 5) USE 'PROLOG_NO_CLAUSES' AND 'PROLOG_SYSPREDICATES' The built-in predicates 'prolog_no_clauses' and 'prolog_syspredicates' can be used to cut down on compilation and running time. See PLOGHELP * SYSTEM for information on these predicates. 6) See PLOGHELP * SYSTEM for more information about tuning. 7) Avoid unwitting production of ratios as a result of using "/" with integers. See REF * EFFICIENCY -- RELATED DOCUMENTATION ---------------------------------------------- PLOGHELP * SYSTEM Predicate which affect the way the Prolog system operates REF * EFFICIENCY This gives many tips relating to efficiency in POPLOG, mostly relevant to POP-11 programmers. However, advanced PROLOG programmers may be able to make good use of the information. REF * FASTPROCS Gives information about fast non-checking procedures available for system programming. HELP * POPMEMLIM Explains some of the background to PLOGHELP * SYSTEM ------------