Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1duPWN-0002a6-Q2 for pgsql-committers@arkaria.postgresql.org; Tue, 19 Sep 2017 20:53:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1duPWN-0004bR-CR for pgsql-committers@arkaria.postgresql.org; Tue, 19 Sep 2017 20:53:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1duPW7-00040V-QX for pgsql-committers@postgresql.org; Tue, 19 Sep 2017 20:53:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1duPW4-00089G-RU for pgsql-committers@postgresql.org; Tue, 19 Sep 2017 20:53:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v8JKr9XM001507; Tue, 19 Sep 2017 16:53:09 -0400 From: Tom Lane To: Andres Freund cc: pgsql-committers@postgresql.org Subject: Re: pgsql: Speedup pgstat_report_activity by moving mb-aware truncation to In-reply-to: <20170919203239.lshzqs4fqnpeo7sg@alap3.anarazel.de> References: <32707.1505852731@sss.pgh.pa.us> <20170919203239.lshzqs4fqnpeo7sg@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Tue, 19 Sep 2017 13:32:39 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1505.1505854389.1@sss.pgh.pa.us> Date: Tue, 19 Sep 2017 16:53:09 -0400 Message-ID: <1506.1505854389@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-committers Precedence: bulk Sender: pgsql-committers-owner@postgresql.org Andres Freund writes: > On 2017-09-19 16:25:31 -0400, Tom Lane wrote: >> Looks like you're going to need to not depend on strnlen(). > Yup noticed - we have pg_strnlen as a static function in > src/port/snprintf. I'm tempted to just make that public, rather than > open code the equivalent? No, we should not tie this to whether we're using port/snprintf.c. Personally, I don't see why this isn't coded more like int rawlen = strlen(activity); rawlen = Min(rawlen, pgstat_track_activity_query_size - 1); It seems likely to me that strlen() is going to be optimized a lot harder than strnlen() on most platforms, so that this way would win not only for strings up to pgstat_track_activity_query_size but for strings some way beyond that. Yes, for really really long queries the strnlen way would win, but that's optimizing for the wrong case IMO. If you really insist on strnlen() then we're going to have to move it to its own src/port/ file with a configure test. regards, tom lane -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers