The -O option
"Richard A. O'Keefe" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Recently I've been trying to improve the performance of some Prolog code. One part of it manipulated subsets of a small known universe as lists. I decided to replace this by bitwise operations. For example, Set /\ (Set - 1) =\= 0 lets you test whether a set has 2 or more elements. To my astonishment, this made the code take *more* time and *more* memory. Then the light-bulb went on. "I need the -O option!" That made all the difference: the code now ran 30% faster, allocating 30% less memory. As long as version 7 is making major changes to the core language, this might be a good time to make the -O option the default. I do appreciate that SWI wants to recover the original term representing a clause, but it could be done like this: begin_fast_arithmetic L1 <optimised code> end_fast_arithmetic L2 L1: <unoptimised code> L2: The execution engine can treat begin_fast_arithmetic as a no-nop and end_fast_arithmetic as an unconditional branch, while the decompiler can do it the other way around.