Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v9E8l-00D2pw-O5 for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 02:54:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v9E8k-009XsI-E9 for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 02:54:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v9E8k-009XsA-4a for pgsql-hackers@lists.postgresql.org; Thu, 16 Oct 2025 02:54:53 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v9E8h-0020lh-0b for pgsql-hackers@postgresql.org; Thu, 16 Oct 2025 02:54:52 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-33bb0472889so103565a91.0 for ; Wed, 15 Oct 2025 19:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760583290; x=1761188090; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0LjZWwIkqkoCeDAav78a1jMiCoUGS6ID+712pZMF9Sc=; b=FGTUPMXCvIDIG7l/Yvm2M9CQKND2aomyLIs54lMmZNrjlXaOFn3C9PO+KTrgCplVtj Mqz33vpVRTnl/4EOkX59WEIFxVhGCOpdeLwq1UgKCvd9VMrTTFW/zURi4QjH5C6vNKiV dz+goKP19YXR9hrzLLVyHUKQahK25Q08XX5Fx80s8VF1EVIajCen63LTLSqDq1TxpuJe R8cPRZV0q9tUVLhcMkZAEV53gynLegD7Ci89ur59vHUcSQSpQlTTEu76lBPz6f+6IYXm 1ESDfLpPFHppVDlrJDYqiPTPcO71IvdeUh0eGK2LaTqr6FYFj5np8boUbuJSmGEI/M8p YDVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760583290; x=1761188090; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0LjZWwIkqkoCeDAav78a1jMiCoUGS6ID+712pZMF9Sc=; b=fPUhInNXukNRQFLqKvaBTPpfPUjxRvf554rwDuQsF/5i45u5r5+84NEek2q/6WQe5R 2InJK3bRDTsDuMVUetUZmyPUS3pycIAJHoAvViCi3BppbEZO6WQmVememuNNYW1Luo2K kPSqx0oREt/1T65FIM77OvDgAMB4EqvM9+l9ze4tcZRhLY27NZdcm7aR4T9SeldcV4ds Y7Q8pmIbpQyOjuovZGNrx6I3RLZXlM/EFbGPhS2aIX7uKil2Xz5fZXXIBPMDRspqRRSE vywKKeYvXXuZwLt8NKNQt/O06jKNLtoqlTE3lFS6HryrOD9sYjiNFXKMKyo3Q2e+v5Es Laog== X-Forwarded-Encrypted: i=1; AJvYcCWaV6diVs5fntASFXPAudSUyQeVDp2JMh+XBGFw92iYKulHpudjRBErvQT4mw5qV8UizVlcp3HFganhPH/K@postgresql.org X-Gm-Message-State: AOJu0Yz3afuUreUPm6vm9z1MuNasQGdW7hOEt9fDMnTvvmPZCIeQYhBq vMWULBQrnpCkJeq5a6uVa4CB0/h13o0sTxXLnMs8htsdCC2cYDlloo+Q X-Gm-Gg: ASbGncszj9S/imxT/dZIFgYiELBEoHFHA8mqes+8En8nYJOJzYE9ux/qtyk1UHaxZys AaZZ65cGuyT7RKVKX6dzfWsepCeFS5kequPIavFz6jDSbhMY5wDLk2ZCfGShqOwktzzQXDKuJqy H/iG2I15m77C+mfljkbwN+AHKzpvWJpce6lN/rhxq7MeRBwtHw9YJhMwvBqKyah/WvepQ+to2EE bkBFbX7PWj1cL8T31opNLbwfoDVTn5UNAZJjoZGuKWKXbEF6U62/Pyw0i+bUL/d0FKCfvT36IH5 Lg+bbk/hzEz8YXtIvVsnUt9iT4hnhJuZ2M6DD9pEorsd6VdTOskDTvSwhwdPmYvkWLk8hPb9C6B V9MFSMevZg+Ke8MASUSvkmj743TnoLpwOteIXSkKi4aKpGnudytuWRWvNgQO0FCkqVbmhW4I6ZU SDo/lS6WPTzuaHAKXwxBbzQSKpzDpeF5Ab X-Google-Smtp-Source: AGHT+IGMxXBfbGcBvpMGJOonxIBlsoccMEqMH9NzpsrdeuGdX+f/gRxEiTSqBbzxTUCW8bHKDr0oUQ== X-Received: by 2002:a17:90b:4d08:b0:330:793a:4240 with SMTP id 98e67ed59e1d1-33b513ced41mr40007302a91.31.1760583289866; Wed, 15 Oct 2025 19:54:49 -0700 (PDT) Received: from smtpclient.apple ([170.178.170.211]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-33ba90eb50esm903966a91.10.2025.10.15.19.54.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Oct 2025 19:54:49 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Optimize LISTEN/NOTIFY From: Chao Li In-Reply-To: <0a5a20d3-4621-46b3-b2ab-903f63a20dea@app.fastmail.com> Date: Thu, 16 Oct 2025 10:54:12 +0800 Cc: Tom Lane , pgsql-hackers Content-Transfer-Encoding: quoted-printable Message-Id: <6F913129-ABEF-4004-AAF3-F22FC3429AE8@gmail.com> References: <6899c044-4a82-49be-8117-e6f669765f7e@app.fastmail.com> <165530.1752362320@sss.pgh.pa.us> <02a7cd37-e2fc-4212-8b19-f8c239c95fb8@app.fastmail.com> <96f00bf1-cc9d-4520-9d02-9e14e7767c88@app.fastmail.com> <30c2aa7d-dd6c-4b68-a2e4-f217a1a34acf@app.fastmail.com> <0b4d402a-9ac2-4aa8-acf8-8231dbe579ea@app.fastmail.com> <3095599.1758644879@sss.pgh.pa.us> <0dc6a2cc-5216-4dc1-9dd2-430cafc6095b@app.fastmail.com> <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> <9186C6D0-F7A9-482A-9183-89E530B57E36@gmail.com> <1073593.1759423179@sss.pgh.pa.us> <4bd5e6c4-6fa7-44bb-869d-59a32a331fa8@app.fastmail.com> <85828f29-e72e-4400-94f3-9a69bc8dc239@app.fastmail.com> <2495353.1759860890@sss.pgh.pa.us> <8aeae418-92a6-4bbd-9c06-9574c79e59f7@app.fastmail.com> <2531672.1759868124@sss.pgh.pa.us> <474efa78-337c-41cd-a73a-f845a0115109@app.fastmail.com> <2749343.1759949176@sss.pgh.pa.us> <8bfca2be-1ec0-4e15-aafb-0b7b661fe936@app.fastmail.com> <9eba307f-f2fb-48f0-9507-2e197f39ef9e@app.fastmail.com> <8c71183a-0d28-4bcf-a806-78446ff95404@app.fastmail.com> <1009807.1760476747@sss.pgh.pa.us> <1F7227F5-C33D-4E2C-8511-33F1468590D0@gmail.com> <0a5a20d3-4621-46b3-b2ab-903f63a20dea@app.fastmail.com> To: Joel Jacobson X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Oct 15, 2025, at 23:36, Joel Jacobson wrote: >=20 >> I agree with Tom that GetPendingNotifyChannels() is too heavy and = unnecessary. >>=20 >> In PreCommit_Notify(), we can maintain a local hash table to record=20= >> pending nofications=E2=80=99 channel names. dahash also supports hash = table in=20 >> local memory. >=20 > I'm confused, I assume you mean "dynahash" since there is no "dahash" > in the sources? I see dynahash has local-to-a-backend support, > but I don't see why we would need a hash table for this, > we just iterate over it once in SignalBackends, > I think the local list is fine. >=20 > The latest version gets rid of GetPendingNotifyChannels() > and replaces it with the local list pendingNotifyChannels. Sorry for the typo, Yes, I meant to dynahash=E2=80=9D that you have = already been using it. In v18, I see you are building =E2=80=9CpendingNotifyChannels=E2=80=9D = in PreCommit_Notify() with =E2=80=9CList=E2=80=9D: ``` + /* + * Build list of unique channels for SignalBackends(). + */ + pendingNotifyChannels =3D NIL; + foreach_ptr(Notification, n, pendingNotifies->events) + { + char *channel =3D n->data; + + /* Add if not already in list */ + if (!list_member_ptr(pendingNotifyChannels, = channel)) + pendingNotifyChannels =3D = lappend(pendingNotifyChannels, channel); + } ``` My suggestion of using dynahah was for the same purpose. Because = list_member_ptr() iterates through all list nodes until find the target, = so this code is still O(n^2). Using a hash will make it faster. I used to work on project Concourse = [1]. The system is heavily using the LISTEN/NOTIFY mechanism. There = would be thousands of channels at runtime. In that case, hash search = would be much faster than linear search. [1] https://github.com/concourse/concourse Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/