alessandro-montanari / tuprolog

Automatically exported from code.google.com/p/tuprolog
0 stars 0 forks source link

Serious performance issue in large projects making large use of lists. #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What is the expected output? What do you see instead?
A problem that is solved by SWI-prolog nearly in real time requires more than 
an hour with tuProlog. Code profiling showed that the method Struct.isList() 
consumes more than 90% of the time, and gets called extremely often. Tentative 
caching strategy: trying to cache the return value the first time it gets 
calculated, the overall time consumption reduced by more than 90% but the 
results look incorrect, too (as expected since the class is not immutable).

Original issue reported on code.google.com by AleMont...@gmail.com on 13 Sep 2012 at 2:59

GoogleCodeExporter commented 9 years ago
A first attempt.
The “old” implementation:

public boolean isList() {
     return (name.equals(".") && arity == 2 && arg[1].isList()) || isEmptyList();
}

The changed implementation:

private Boolean isList;

public boolean isList() {
    if (isList == null){
        isList = (name.equals(".") && arity == 2 && arg[1].isList()) || isEmptyList();
    }
    return isList;
}

After these changes the performance was extremely better. But the results look 
different.

Original comment by AleMont...@gmail.com on 13 Sep 2012 at 3:02