Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bjjK5-0004sW-CY for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Sep 2016 08:44:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bjjK4-00068h-Qc for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Sep 2016 08:44:08 +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 1bjjK4-00068R-4P for pgsql-hackers@postgresql.org; Tue, 13 Sep 2016 08:44:08 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bjjK0-0000cM-R3 for pgsql-hackers@postgresql.org; Tue, 13 Sep 2016 08:44:07 +0000 Received: by mail-wm0-x22b.google.com with SMTP id 1so187710989wmz.1 for ; Tue, 13 Sep 2016 01:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=53oI4wBtsp9w9xBf9tyOAALWMhGzudAQB3UVGZNDhHQ=; b=BuRAqk0u8toLkJkI4yKI5K+FaDHNnT7UWp4mg5U+mDnz6CpSFzUpPb1wQvRlyleXRj 5E9GSPzmtm2nDe0Q4+RHCAlJB9lpjAZxV2Goyo31RWRWjrXnKpc8L4ktE4zyu2JQSo6w uGUcU0yc+0toFRezmVUdNzW0x7Jb/oLbm7A/Mje1qN54A+u4Bz1MYPtesOovfa4I+lcQ 0BV15ScvVL7PMLa3L7Zig/aZn8gPnTG+4gd82DMSwRt+rfyBFHIlkBKTHzDIQk4PUMEl ETdNvg4aDH15Krwjz6TSrRQ//oIfSGOXA7BP1lenV3XZJx5dX6wDKhm4G4BGm3yCNPmX SoSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=53oI4wBtsp9w9xBf9tyOAALWMhGzudAQB3UVGZNDhHQ=; b=jccf4yO1u+CkyqJVMmP+beNliyhSR2uGo0QOAGp4EqUVaKl7t/b4y5FBVIyjR1UhW0 fDZhHQTlB1xHyJiWG09LSOrcllf7ElGyEJGw01A7GtnxvJc9p2nLaZwopsve8fnQ7409 24TsMXBp/jujqRnM/irEOu8G3qJ5O0qI6unMKizITAhLMXN+neq1DP9/KMk6IMtPjZaM L4yoc51UeS7eljGla310+4wAK5zGwu2YhkbmuZPyaJRNc6mvxNeFRieSF2yiL6CjevqW rGYIWHWIyv6QA2JasPMx4Me/ADeTp/2maNccprlLcO8snRMj7SuYlgnyKSFKBXLm8zxF wjdA== X-Gm-Message-State: AE9vXwNxR7Ejej/mMIccpPeUaA3ZbT+C21S/L214dnRlC5/z2N9XyEI8Ll4dW+jZ3MCqzA== X-Received: by 10.28.15.3 with SMTP id 3mr3791614wmp.31.1473756243582; Tue, 13 Sep 2016 01:44:03 -0700 (PDT) Received: from [192.168.1.111] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id jd4sm21791549wjb.6.2016.09.13.01.44.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Sep 2016 01:44:02 -0700 (PDT) Subject: Re: Supporting SJIS as a database encoding To: Kyotaro HORIGUCHI , tsunakawa.takay@jp.fujitsu.com References: <20160906.122904.256837704.horiguchi.kyotaro@lab.ntt.co.jp> <0A3221C70F24FB45833433255569204D1F5E66CE@G01JPEXMBYT05> <20160907.161304.112519789.horiguchi.kyotaro@lab.ntt.co.jp> <20160908.153546.187438961.horiguchi.kyotaro@lab.ntt.co.jp> Cc: tgl@sss.pgh.pa.us, ishii@sraoss.co.jp, pgsql-hackers@postgresql.org From: Heikki Linnakangas Message-ID: <7ff67a45-a53e-4d38-e25d-3a121afea47c@iki.fi> Date: Tue, 13 Sep 2016 11:44:01 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160908.153546.187438961.horiguchi.kyotaro@lab.ntt.co.jp> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 09/08/2016 09:35 AM, Kyotaro HORIGUCHI wrote: > Returning in UTF-8 bloats the result string by about 1.5 times so > it doesn't seem to make sense comparing with it. But it takes > real = 47.35s. Nice! I was hoping that this would also make the binaries smaller. A few dozen kB of storage is perhaps not a big deal these days, but still. And smaller tables would also consume less memory and CPU cache. I removed the #include "../../Unicode/utf8_to_sjis.map" line, so that the old table isn't included anymore, compiled, and ran "strip utf8_and_sjis.so". Without this patch, it's 126 kB, and with it, it's 160 kB. So the radix tree takes a little bit more space. That's not too bad, and I'm sure we could live with that, but with a few simple tricks, we could do better. First, since all the values we store in the tree are < 0xffff, we could store them in int16 instead of int32, and halve the size of the table right off the bat. That won't work for all encodings, of course, but it might be worth it to have two versions of the code, one for int16 and another for int32. Another trick is to eliminate redundancies in the tables. Many of the tables contain lots of zeros, as in: > /* c3xx */{ > /* c380 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* c388 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* c390 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x817e, > /* c398 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* c3a0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* c3a8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* c3b0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8180, > /* c3b8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 > }, and > /* e388xx */{ > /* e38880 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* e38888 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* e38890 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* e38898 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* e388a0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* e388a8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* e388b0 */ 0x0000, 0xfa58, 0x878b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, > /* e388b8 */ 0x0000, 0x878c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 > }, You could overlay the last row of the first table, which is all zeros, with the first row of the second table, which is also all zeros. (Many of the tables have a lot more zero-rows than this example.) But yes, this patch looks very promising in general. I think we should switch over to radix trees for the all the encodings. - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers