Stavros Macrakis | 7 Sep 17:49
Favicon

reverse and nreverse in nset performance review

Andreas,

In reviewing the performance of the set functions, I noticed that there was a call to "reverse" in do-merge-asym where an "nreverse" would make more sense.  I wrote this code, so I was embarrassed to see this elementary oversight.  But then I checked the revision log of nset, and discovered that it was you who had made this change in nset.lisp 1.20 -> 1.21 (March 2007). Barton had also pointed this out to me last year, but I wasn't focussed on nset at the time.

Nreverse is of course a destructive operation and reverse is a non-destructive (copy) operation, so nreverse is suitable when it is known that a list structure is unshared (e.g. (nreverse (mapcar ...))) while reverse is suitable when a list structure may be shared. Nreverse has the advantage of not cons'ing new list structure unnecessarily and in most implementations should be much faster than reverse.(*)

I had used nreverse in do-merge-asym because the list structure here is supposed to be guaranteed to be unshared.  I assume you changed it to reverse in the belief that there are cases where it might be shared. If that is true, then there is a bug in do-merge-asym which should be corrected at the source, not symptomatically.  If it is not true, the only effect will be to increase the amount of cons'ing, which is generally considered a bad thing. WHich is it?

Thanks,

            -s

(*) In some implementations, like the old Lisp Machine Zetalisp, nreverse may actually be less efficient because of special data representations for linear lists.  Do any current Lisp implementations have such a property?

_______________________________________________
Maxima mailing list
Maxima <at> math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima
Andreas Eder | 7 Sep 19:35

Re: reverse and nreverse in nset performance review

Hi Stavros,

>>>>> "Stavros" == Stavros Macrakis <macrakis <at> alum.mit.edu> writes:

    Stavros> Andreas,
    Stavros> In reviewing the performance of the set functions, I noticed that there was
    Stavros> a call to "reverse" in do-merge-asym where an "nreverse" would make more
    Stavros> sense.  I wrote this code, so I was embarrassed to see this elementary
    Stavros> oversight.  But then I checked the revision log of nset, and discovered that
    Stavros> it was you who had made this change in nset.lisp 1.20 ->
    Stavros> 1.21<http://maxima.cvs.sourceforge.net/maxima/maxima/src/nset.lisp?r1=1.20&r2=1.21>(March
    Stavros> 2007). Barton had also pointed this out to me last year, but I wasn't
    Stavros> focussed on nset at the time.

    Stavros> I had used nreverse in do-merge-asym because the list structure here is
    Stavros> supposed to be guaranteed to be unshared.  I assume you changed it to
    Stavros> reverse in the belief that there are cases where it might be shared. If that
    Stavros> is true, then there is a bug in do-merge-asym which should be corrected at
    Stavros> the source, not symptomatically.  If it is not true, the only effect will be
    Stavros> to increase the amount of cons'ing, which is generally considered a bad
    Stavros> thing. WHich is it?

Since it is about 1 1/2 years ago now I am no longer quite sure
what it was, but I think I was concerned about do-merge-asym might
share data.
If you are sure this is not so, you could surely change it back.

Sorry for any inconvenience that micht have given you.

Thanks,

Andreas

--

-- 
ceterum censeo redmondinem esse delendam.
Stavros Macrakis | 8 Sep 02:38
Favicon

Re: reverse and nreverse in nset performance review

On Sun, Sep 7, 2008 at 1:35 PM, Andreas Eder <andreas_eder <at> gmx.net> wrote:
Since it is about 1 1/2 years ago now I am no longer quite sure
what it was, but I think I was concerned about do-merge-asym might
share data. 
If you are sure this is not so, you could surely change it back.

Next time, if you are sure there is a problem, please document it along with your code change.

If you suspect there is a problem but cannot find a failing test case, please leave it alone or query the implementor rather than changing it. There is a lot of subtle code in Maxima.

          -s

_______________________________________________
Maxima mailing list
Maxima <at> math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima

Gmane