Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxwhD-0002qk-Px for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Jun 2021 19:13:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lxwhB-0007Xh-HV for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Jun 2021 19:13:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxwhB-0007XY-79 for pgsql-hackers@lists.postgresql.org; Mon, 28 Jun 2021 19:13:25 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lxwh6-0005ff-7m for pgsql-hackers@postgresql.org; Mon, 28 Jun 2021 19:13:24 +0000 Received: by mail-io1-xd2a.google.com with SMTP id i189so23617291ioa.8 for ; Mon, 28 Jun 2021 12:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rJ29SpV59++eHBmPtMC7eHetdi/TOSMrlWZq1ggt4Xc=; b=XEM+VcVhJ7xK/CHM5MPo7IxuvmIH2Pz5us2JvmJg/l9lEX83vjvEKmtttOUa9MysCu hUYgU4AKoVMSy4ueTJvin9BS9otncKzwOVy0vxuJODjqqdgBjCgBMezKpwO1XOrWxklf //LWKWDcQi45+gjmpcd0p4BW4CE6gyymVBA8XWOFm02X8Gfi8eDHTEae6Dwl6Yj2EadB FIUuKbw04H2Vz6ZrPlsQKC3UasuqB+vQGJj9DGW6vfwC3e3ItOg9wqu13DMknp01q/Nz 0f84Xqfp4e+WArDJW/XSqaqyiS4wnCgBga5Xxa0buzSQZcMBdah3TCGGqzjz1EyWDLIa MZVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rJ29SpV59++eHBmPtMC7eHetdi/TOSMrlWZq1ggt4Xc=; b=jaM9qp1HJfgFfPw6z6OAW7zWNfm+1veNyOoVrYYIrwl70gKUUi++msJFleTCQ2RhP8 kvLM1+PzhurSPbggKTGyHGdHeoJlTqPdoH2KXme+2wCkzmzdVZj5v/ziLWuEUNqNZsx1 3yRqenUYmX6wdRHUD9nUlQoOShPSwNXNTfewN0m/dV6h2lTpk3b1vsQISKfPioiHdJEh +Ij4AfIWyhf2EY20/NLjWw6xBcTu6gVGDijooyt05OUoZgWs0hRo5T+D38Af8LPQypa4 2MuwtPuh3f9r3Yy0elu6hiIr+g5ggK/c/lidVEul4d+A0pMAUJ0h7phMM4uuT8crTe2F hTfA== X-Gm-Message-State: AOAM532VIaI0fsnAS1+L0d304udMjGyitKh6I4jbIau++SckMgLBeY+L 4Yur3dw+BEvBTZagnJ69V/Ml11LWk5cZ+ybCqvX34DsraL5bhOZ+uvgIV2wYrUUXTlJDacca8k7 zRFZRzzcZKgGMnZnLIl8n9Ml6/lPzAHlEnoB8R+U4Jvxinp3DSm2MImB4mhrl4OGWccEleSLT66 orsTYwUjospGazd8g9xxwPCUu2Bl4O9STQ4GFrDNYofiZGErvQo204Yy3UDQZB X-Google-Smtp-Source: ABdhPJzjYUnXY4o7xTCr0r5V09FonPJdegNXU5YAa3AgZp8ZEPkGbJOs+oGmLxPoTxtKtjGynU6FkwhDMsb8bpN9bfk= X-Received: by 2002:a5d:9c43:: with SMTP id 3mr740932iof.123.1624907598030; Mon, 28 Jun 2021 12:13:18 -0700 (PDT) MIME-Version: 1.0 References: <0F9ECBA9-1DF2-4C38-BB58-B17EEE6C7B3A@yesql.se> <20210311185847.zwb2rf3n4wzelkba@alap3.anarazel.de> In-Reply-To: From: John Naylor Date: Mon, 28 Jun 2021 15:13:06 -0400 Message-ID: Subject: Re: A qsort template To: Thomas Munro Cc: pgsql-hackers Content-Type: multipart/alternative; boundary="0000000000002c80ec05c5d8486c" X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002c80ec05c5d8486c Content-Type: text/plain; charset="UTF-8" On Wed, Jun 16, 2021 at 1:55 AM Thomas Munro wrote: [v2 patch] Hi Thomas, I plan to do some performance testing with VACUUM, ANALYZE etc soon, to see if I can detect any significant differences. I did a quick check of the MacOS/clang binary size (no debug symbols): master: 8108408 0001-0009: 8125224 Later, I'll drill down into the individual patches and see if anything stands out. There were already some comments for v2 upthread about formatting and an overflow hazard, but I did find a few more things to ask about: - For my curiosity, there are a lot of calls to qsort/qunique in the tree -- without having looked exhaustively, do these patches focus on cases where there are bespoke comparator functions and/or hot code paths? - Aside from the qsort{_arg} precedence, is there a practical reason for keeping the new global functions in their own files? - 0002 / 0004 +/* Search and unique functions inline in header. */ The functions are pretty small, but is there some advantage for inlining these? - 0003 #include "lib/qunique.h" is not needed anymore. This isn't quite relevant for the current patch perhaps, but I'm wondering why we don't already call bsearch for RelationHasSysCache() and RelationSupportsSysCache(). - 0008 +#define ST_COMPARE(a, b, cxt) \ + DatumGetInt32(FunctionCall2Coll(&cxt->flinfo, cxt->collation, *a, *b)) This seems like a pretty heavyweight comparison, so I'm not sure inlining buys us much, but it seems also there are fewer branches this way. I'll come up with a test and see what happens. -- John Naylor EDB: http://www.enterprisedb.com --0000000000002c80ec05c5d8486c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Jun 16, 2021 at 1:55 AM Thomas Munro <thomas.munro@gmail.com> wrote:[v2 patch]

Hi Thomas,

I plan to do some performance tes= ting with VACUUM, ANALYZE etc soon, to see if I can detect any significant = differences.

I did a quick check of the MacOS/clang binary size (no = debug symbols):

master: =C2=A0 =C2=A08108408
0001-0009: 8125224
Later, I'll drill down into the individual patches and see if any= thing stands out.

There were already some comments for v2 upthread a= bout formatting and an overflow hazard, but I did find a few more things to= ask about:

- For my curiosity, there are a lot of calls to qsort/qu= nique in the tree -- without having looked exhaustively, do these patches f= ocus on cases where there are bespoke comparator functions and/or hot code = paths?

- Aside from the qsort{_arg} precedence, is there a practical= reason for keeping the new global functions in their own files?

- 0= 002 / 0004

+/* Search and unique functions inline in header. */
=
The functions are pretty small, but is there some advantage for inlinin= g these?

- 0003

#include "lib/qunique.h" is not nee= ded anymore.

This isn't quite relevant for the current patch per= haps, but I'm wondering why we don't already call bsearch for Relat= ionHasSysCache() and RelationSupportsSysCache().

- 0008

+#def= ine ST_COMPARE(a, b, cxt) \
+ DatumGetInt32(FunctionCall2Coll(&cxt-&= gt;flinfo, cxt->collation, *a, *b))

This seems like a pretty heav= yweight comparison, so I'm not sure inlining buys us much, but it seems= also there are fewer branches this way. I'll come up with a test and s= ee what happens.

--
John Naylor
EDB: http://www.enterprisedb.com
--0000000000002c80ec05c5d8486c--