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 1umZ9I-0009z3-VV for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Aug 2025 14:41:49 +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 1umZ9H-006xnX-8A for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Aug 2025 14:41:47 +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 1umZ9G-006xnL-VD for pgsql-hackers@lists.postgresql.org; Thu, 14 Aug 2025 14:41:47 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1umZ9E-000Ydf-1s for pgsql-hackers@postgresql.org; Thu, 14 Aug 2025 14:41:45 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-55ce520c9acso1064764e87.1 for ; Thu, 14 Aug 2025 07:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755182503; x=1755787303; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=1yYvVO8X7C0ThgFpAfyLeJdeUcUBpm7yv0YfADCIu9A=; b=aBPyD6lyglefjuJQheSVp+aoSLpxdNSN6aefy5nnHjPM9m+6MYuLQJ2Rs+zA1uPm0j GfHxQIK5gPrXIOSUtuH5VYMVtfUPFrepYTctugkFGxi5gd8zn2dgn5C2RX9xcxlmTeTr zSBetXD7cb11K1W1l7CIc1s5gNMPYr1G3P6w0Jm0ZH8ts0tcuFYG8iQvQR7v83R9UlBN PMCLNS1+cyn8q24E0hW3AYmUu20G+YQLZn/JdkRnW1uR4vMt4/ADuPnyzsJEOfwl3aJP ScIYK3m7J57tKOZ75smmEAS5WFAF4ED6gJH8hoikfYKL/DLYRnD2yaZiBqC9PGeXyrfY CbcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755182503; x=1755787303; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1yYvVO8X7C0ThgFpAfyLeJdeUcUBpm7yv0YfADCIu9A=; b=DoNmXiCkyD3ltkTxrIkzyi9ZmXIC71YhvmxM4gGMStmdMJJM2YyKRkO4bm+HbqRUd+ Nlmj/OSikUP1k3RT0eUXeygafMUZAnQqvO1aH1E35cVqesj7KN5mnJSbT1EVW4LerVvI R5Qjq2z8klGEc+cJyiKTbE5GzYyNdvIa3CkIXbhKTmOkDI4DVxwK8LTZVtuLL6+kfvBr XDdEyLSh4FFtfWQx0tmVrcH5JXRv80A6nhqQ+otk/rJ4RZ/zlbdlA1UCHfB5gCRQVUPV bJpFLLyYfH0+1f69XIz25WEsZXPu9Vin4PTFPVMR/661BYIou4NXWb5cniLS+yZ51kyU pvcg== X-Forwarded-Encrypted: i=1; AJvYcCUwuI2JMR1n1Sj1cCSI6HsSP2RZv9oLqHXtKCazAwVsZ/11GtKCBkdXh2TcmdR5a3e+HqrOO54f1Ee74mzB@postgresql.org X-Gm-Message-State: AOJu0Yyrb6Aw3Cav+5WkPo24bXdXyGMkpRgxA0Xi+qMUxUX2mMb4n5md kC2ETQuuHCPMuCG7DT7Qn/DvVsGAZ0gP155MMn6+yPLKFFPxtOwrqZ3oizUS90e7 X-Gm-Gg: ASbGncupLW+1gS/qoPp0sBF/6OTX+2OTUo2kgTyJRjhJhBLhBHI6AJ8XqoM/+4fpmfI z282OlvoNf51598SFnjGTztfA7XA+QADcsWFScM0kX5wFxHOHW14glpBCHK70mkqWQdHZa8DYOr qqe+UUZtgOfLU3dBD4G72nmzvWj2jWOB3TC5Hh0cf/TQ2lpZMzdp/K70TjuGheINkJuN+kum3EB b0UpYO65LAU5jucQ8pEt2NR+PZwLGzHJlAWQTA71wHSYSJKQekQCoaFS5eiMx937hD8YhTermWa EggDkzW+DtETVQWrnkWgjC/nrozH/V+D+oj6FAcQhl4gzbc6eyxNKyYfhfrNfm7T499YL6ufZwB m8TPfedc6jO0uAWrzVh2IyNKlKuv55wW4z5D6uLhBMQD2g1gxWdioKHzgShqMYS7/JxxKHDkHRk PzoHt1jAxA X-Google-Smtp-Source: AGHT+IE6llHTUzVRW33zzRs2jk3n349VQ1i3C8J5BCbjbX2Yt1PHZJY08Ce5bz8E1h2T9HodXk7KFw== X-Received: by 2002:a05:6512:1304:b0:553:a469:3fed with SMTP id 2adb3069b0e04-55ce503298amr1208130e87.11.1755182502991; Thu, 14 Aug 2025 07:41:42 -0700 (PDT) Received: from [192.168.50.127] (broadband-5-228-116-129.ip.moscow.rt.ru. [5.228.116.129]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-55b9fa8c216sm4655665e87.25.2025.08.14.07.41.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Aug 2025 07:41:42 -0700 (PDT) Message-ID: <1260f607-8d90-4cf2-accc-45aa6eab63d8@gmail.com> Date: Thu, 14 Aug 2025 17:41:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Improve the performance of Unicode Normalization Forms. To: Jeff Davis , PostgreSQL Hackers References: <844d3dd7-2955-4794-95d1-7f4c13cb89fc@gmail.com> <4211ffd7fe154c4af693b98d78f4a3689ce8cc30.camel@j-davis.com> <16f87504-f174-450e-93cc-2db1074522bb@gmail.com> <96c54fc3dde2ebaccafbd1ffa29b8be1005c8b8c.camel@j-davis.com> <677cde50-6d64-474b-9ba8-bab380a111b3@gmail.com> <599663a8d5948243bd87bf55a4f76bbb4a51a6e8.camel@j-davis.com> <85f2a36f-f70a-4667-be48-49b652457295@gmail.com> <088432f3-a3a9-4c40-8295-6c687c25d651@gmail.com> Content-Language: ru From: Alexander Borisov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 14.08.2025 01:12, Jeff Davis wrote: > On Mon, 2025-08-11 at 17:21 +0300, Alexander Borisov wrote: [..] > > Comments on the patch itself: > > The 0001 patch generalizes the two-step lookup process: first navigate > branches to find the index into a partially-compacted sparse array, and > then use that to get the index into the dense array. The branching > code, the sparse array, and the dense array are all generated code. The > reason for the two-step lookup is to keep the sparse array element size > small (uint16), so that missing elements consume less space (missing > elements still remain for small gaps). The full entry is kept in the > dense array. Yes, that's exactly right. > GenerateSparseArray.pm would be more descriptive than "Ranges.pm" for > the new module. And we should probably include "sparse" in the name of > the sparse arrays. I don't mind, that's good. > The new module is responsible for generating the branching code as well > as the sparse array; while the caller is reponsible for the dense > arrays. For case mapping, one sparse array is used for four parallel > arrays for the different case kinds (lower/title/upper/fold). Yes, that's right. > The use of zero values for different purposes is getting confusing. It > means "doesn't exist", but we are also reserving the zeroth element in > the arrays. Would it be easier to just "#define EMPTY 0xFFFF" and then > have the caller check for it? That way we don't need to reserve the > zeroth array element, which should make it easier to avoid off-by-one > errors. Initially, that was the case; However, I subsequently concluded that creating magical values to define an element that was not found was not an ideal solution. I felt that 0 was easier to understand. I'm not entirely sure now, but maybe this will even help get rid of the comparison to 0. That is, we can get an element from the main table by index 0. It will be zeroed, and the algorithm will work as it should. However, it is not certain that this will have any effect on performance. In general, I don't have a firm position on this issue. > I think we can simplify the interface, as well. Why does the caller > need to separately generate the ranges, then generate the table, then > generate the branches? It's really all the same action and can be based > on an input hash with a certain structure, and then return both the > table and the branches, right? Yes, it can be done in one go. But the separation was done intentionally. It makes the code more understandable, and, more importantly, it makes it easier for developers "from the street" to understand it and, if necessary, correct or supplement the algorithm. These are utilities, code for generating an algorithm that, let's say, will not be used very often, and I would not "compress" it. Here, it is more important for us to understand how it works. -- Regards, Alexander Borisov