equal() perf tweak

From: Neil Conway <neilc(at)samurai(dot)com>
To: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: equal() perf tweak
Date: 2003-11-03 14:00:34
Message-ID: 1067868034.3089.225.camel@tokyo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Currently, equal() does the following for List nodes:

case T_List:
{
List *la = (List *) a;
List *lb = (List *) b;
List *l;

/*
* Try to reject by length check before we grovel through
* all the elements...
*/
if (length(la) != length(lb))
return false;
foreach(l, la)
{
if (!equal(lfirst(l), lfirst(lb)))
return false;
lb = lnext(lb);
}
retval = true;
}
break;

This code is inefficient, however: length() requires iterating through
the entire list, so this code scans both lists twice. The attached patch
improves this by implementing equal() with a single scan of both lists.

-Neil

Attachment Content-Type Size
equal-list-perf-1.patch text/x-patch 1.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Sullivan 2003-11-03 14:16:37 Re: adding support for posix_fadvise()
Previous Message Neil Conway 2003-11-03 13:50:00 Re: adding support for posix_fadvise()

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2003-11-03 15:00:25 Re: bufmgr code cleanup
Previous Message Jan Wieck 2003-11-03 13:31:55 Re: bufmgr code cleanup