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 1tkWUD-004ixm-Sl for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 22:54:41 +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 1tkWUB-001dak-Vq for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 22:54:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tkWUB-001dac-Ly for pgsql-hackers@lists.postgresql.org; Tue, 18 Feb 2025 22:54:39 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tkWU9-001e8D-13 for pgsql-hackers@postgresql.org; Tue, 18 Feb 2025 22:54:39 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-5439e331cceso6960510e87.1 for ; Tue, 18 Feb 2025 14:54:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739919276; x=1740524076; 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=OWueX9G+cgOiVIWHFNXlOpX+mVWa1qgUWjch5wTyDRo=; b=XHpsWAA/8RGQHQnSUNsH9oz0qT/y3SamBNOCWzlM7SDtf6iYk8PQIc/Wkz23Y8HbM1 O3uswLDu4P1+c+ToVQwWjI8nRW0P+srMmpASS06czFVlVnItClkuuguuFFqJfqkt3ta7 2Ri6D0HUhlTTfJvf2UPZXAnISgy7MlVF5O5v0S1R1dNk8Ox7v+tGlcClOMfWGijH9IwJ POva30aEMd/sRAkH266RuThuTo9YJ4WAm4tkvxu3GFZF29M9+E7EWvX0BasaGe5u4Ggy aLqYjAm6+M/uvyaxDORsDWEpIN1jN/aXpFe9rsNx1L37BI0HG68mY6L1YLlbAiv9K5+w M+Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739919276; x=1740524076; 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=OWueX9G+cgOiVIWHFNXlOpX+mVWa1qgUWjch5wTyDRo=; b=m+0pzTNayby1MJtIFUMpOSa+EPRjJB0AcvjFUQPr6Vr9yo2VjuCkp9yS9zFzEYlh5P SvbaJH5SdUMHLA4XTBA1xUCdlvyxz+X6qPdOzVPbszDZrlZSXD7rbi+5OmcVPEJeDZ5h HG8j9utNkkp6XiBvnSBdYdm4WYE7HCWVPvIeUrBL6m60EFDjNb+ovrdf6X8QhU6IP/Ah MFM+xpvU73CaaEzXjhWjP9Q8PJIpryouhTxfjNia7nPmVVuOtQ4t8LLwIPgHcINfaHt8 r2WogUO5l8foAKtVK32ugxtTPLWPAFByjibM4W4ZhmFN9+U3dwgxprihHPTEV80NhYTc CTKg== X-Forwarded-Encrypted: i=1; AJvYcCWeJoJRp5b+nr84HqK2imUPlhizkM7zmUH5IoEfWffHx7rbsx2Cw/3u7fZLu8zAqSxb5es/VpYOY1gY4d+e@postgresql.org X-Gm-Message-State: AOJu0Yx9yZpATGEMgH2xgtK4HF5P6rWTJ3ZitHg5P88uA1aCvcxm/Gbe kjwmLSj0VBGQCOnmc7J65tI5F4f/aounPFK/I3FZ3aL7qQn+B3dl X-Gm-Gg: ASbGncsFBK0Trzq+C+GbzchU1Ga1+4HIBFbYX+NZkydxDnwbvkSfvFrPcGnWUbTG3T2 eyv4ur+IaHmMKIkbBoEjGH+HdV19j8toyE69Vzsh6CA24I0cAxnwkVoHB9zhcM/NotxAskJmgUQ oA8I1TU0AVMivaqDsWQQUFpZ0is/GwcHVZhGPw3aNLXRa03NGbfmPYKIDCKK68HkAYWaJBsuacQ 7OEGNghgM+XgmwDOmxh1rCawhRjweTlgOaNaOvaYhtNJ/rl7IDvJWyFRdEoX3tWXzB4BJzm2rqN FgRA5MhJvZuehizHKRX0pn6WMO1BFi1Pmtx/2+qU2KY8nO7NCJabCJY3qNhhkQLkWZ6BWXUq1A= = X-Google-Smtp-Source: AGHT+IFvvWIo4G0jkSRG25+PBt29GRpKHtzR3zg/sEESv8IoszMz+Wt/rKxaroh77KNnIVygFYvVSg== X-Received: by 2002:a05:6512:15a6:b0:545:c23:9a94 with SMTP id 2adb3069b0e04-5462ef20fa5mr513971e87.48.1739919276158; Tue, 18 Feb 2025 14:54:36 -0800 (PST) Received: from [192.168.50.127] (broadband-188-255-2-52.ip.moscow.rt.ru. [188.255.2.52]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5452de0bf85sm1584060e87.132.2025.02.18.14.54.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Feb 2025 14:54:35 -0800 (PST) Message-ID: Date: Wed, 19 Feb 2025 01:54:35 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Optimization for lower(), upper(), casefold() functions. To: Jeff Davis , Heikki Linnakangas , pgsql-hackers@postgresql.org References: <7cac7e66-9a3b-4e3f-a997-42aa0c401f80@gmail.com> <2a1b632e-4531-43cf-a6d9-51cc1a271dc1@gmail.com> <7ab9d255-d7c0-4841-96c3-ed3ce9aa4abd@iki.fi> <12956299-1496-4455-b3ab-299cc0a87d7c@gmail.com> <340f2451-cd76-487b-a1e4-0f0a2fe91fba@gmail.com> <3ffb8b75b26e76624668c0883cac7886468c5d07.camel@j-davis.com> <5cf176fa-44b9-4019-b9b7-ee902352a844@gmail.com> <3080de9bcce916cf8720ac197f634e381c4de564.camel@j-davis.com> <1e3f4f6f-9b12-4109-b0d2-a4c52b5064f8@gmail.com> Content-Language: ru From: Alexander Borisov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 19.02.2025 01:02, Jeff Davis пишет: > On Tue, 2025-02-11 at 23:08 +0300, Alexander Borisov wrote: >> I tried the approach via a range table. The result was worse than >> without the table. With branching in a function, the result is >> better. >> >> Patch v3 — ranges binary search by branches. >> Patch v4 — ranges binary search by table. > > Thoughts on v3: > > It looks like the top 5 bits of the offset are unused. What if we used > those bits for flags to indicate: > > HAS_LOWER > HAS_UPPER > HAS_FOLD > HAS_SPECIAL > HAS_TITLE > > That way, we only need to look in the corresponding table if it > actually has an entry other than the codepoint itself. > > It doesn't leave a lot of room if the tables get larger, but if we are > worried about that, we could eliminate HAS_TITLE, because I don't think > the performance for INITCAP() is as important as LOWER/UPPER/CASEFOLD. > > Regards, > Jeff Davis > It seems to be micro-optimizations. In the sense that the code is very clear and understandable now. These micro-optimizations make the code more complex, and there will be no performance gain. In proposing the patch for v3, I struck a balance between improving performance and reducing binary size, without sacrificing code clarity. We can go into micro-optimizations now and lose the essence of the proposed improvements. And ahead of us we have Unicode Normalization Forms. I'm willing to try different approaches, but there's confidence that we've found a great optimization right now. -- Alexander Borisov