Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iRC7w-0001jf-MF for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Nov 2019 09:24:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iRC7t-000752-45 for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Nov 2019 09:24:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iRC7s-00074u-Iy for pgsql-hackers@lists.postgresql.org; Sun, 03 Nov 2019 09:24:48 +0000 Received: from www3.webmail.pair.com ([66.39.3.34]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iRC7p-0002OD-O4 for pgsql-hackers@lists.postgresql.org; Sun, 03 Nov 2019 09:24:47 +0000 Received: from rc.webmail.pair.com (localhost [127.0.0.1]) by www3.webmail.pair.com (Postfix) with ESMTP id A0DE73E0093; Sun, 3 Nov 2019 04:24:43 -0500 (EST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Sun, 03 Nov 2019 10:24:43 +0100 From: Tels To: Andrey Borodin Cc: Tomas Vondra , Alvaro Herrera , Peter Eisentraut , Gasper Zejn , pgsql-hackers@lists.postgresql.org Subject: Re: pglz performance Organization: Highly Unorganized Reply-To: nospam-pg-abuse@bloodgate.com Mail-Reply-To: nospam-pg-abuse@bloodgate.com In-Reply-To: <27F232D7-25C5-4D12-AFA0-50EEBAB98E9C@yandex-team.ru> References: <3c2d92d0-e715-f9ed-e1a7-3c510ed65940@2ndquadrant.com> <20191101154828.GA15829@alvherre.pgsql> <20191101165950.b5azncggaqfan5fi@development> <27F232D7-25C5-4D12-AFA0-50EEBAB98E9C@yandex-team.ru> Message-ID: X-Sender: nospam-pg-abuse@bloodgate.com User-Agent: Roundcube Webmail/1.3.8 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello Andrey, On 2019-11-02 12:30, Andrey Borodin wrote: >> 1 нояб. 2019 г., в 18:48, Alvaro Herrera >> написал(а): > PFA two patches: > v4-0001-Use-memcpy-in-pglz-decompression.patch (known as 'hacked' in > test_pglz extension) > v4-0001-Use-memcpy-in-pglz-decompression-for-long-matches.patch (known > as 'hacked8') Looking at the patches, it seems only the case of a match is changed. But when we observe a literal byte, this is copied byte-by-byte with: else { * An unset control bit means LITERAL BYTE. So we just * copy one from INPUT to OUTPUT. */ *dp++ = *sp++; } Maybe we can optimize this, too. For instance, you could just increase a counter: else { /* * An unset control bit means LITERAL BYTE. We count * these and copy them later. */ literal_bytes ++; } and in the case of: if (ctrl & 1) { /* First copy all the literal bytes */ if (literal_bytes > 0) { memcpy( sp, dp, literal_bytes); sp += literal_bytes; dp += literal_bytes; literal_bytes = 0; } (Code untested!) The same would need to be done at the very end, if the input ends without any new CTRL-byte. Wether that gains us anything depends on how common literal bytes are. It might be that highly compressible input has almost none, while input that is a mix of incompressible strings and compressible ones might have longer stretches. One example would be something like an SHA-256, that is repeated twice. The first instance would be incompressible, the second one would be just a copy. This might not happens that often in practical inputs, though. I wonder if you agree and what would happen if you try this variant on your corpus tests. Best regards, Tels