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 1uSd5X-00Al4b-NT for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jun 2025 14:51:31 +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 1uSd5V-002GQG-21 for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jun 2025 14:51:29 +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 1uSd5U-002GQ7-OU for pgsql-hackers@lists.postgresql.org; Fri, 20 Jun 2025 14:51:29 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uSd5T-0034ZY-2D for pgsql-hackers@postgresql.org; Fri, 20 Jun 2025 14:51:28 +0000 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-32b910593edso13064491fa.1 for ; Fri, 20 Jun 2025 07:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750431086; x=1751035886; 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=O/DTPZXobc5NH0DErZtGO9ylMIbi6oC2TzPZYqpfZB8=; b=Ctbd0s8VVQdhjKVD1B16+xsmJWy4u9tP3+RNujaoTc1vOvyYQ3jTBfR7On5G/Tos2l b+h/ox/AJ+tNcP7xMqPsF/2ffH88v7e9AOZownGpnNZWYzixGz1mzSnCN4+o2kvcg/R5 tZ+5f45jhMS2yj9vLFEKMkXrzREtlrgAbxHJ4vMHs8NkxRi1ykwahywHXFb0vOfhNSRw tBS18swtWm8qpGZ9OPFDTPijtVzYBkKmuIIOUENSctIFYuzmHvCv3fA9zojomkidpiJo WADr4wc9SOO5uAnKhspI40WZhVuWVlBpo2MSuNpoW8YwFdbQOURpk1vvXqH2LcVCdZjs V3yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750431086; x=1751035886; 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=O/DTPZXobc5NH0DErZtGO9ylMIbi6oC2TzPZYqpfZB8=; b=PyU+2jaSl9DunihdBqrPZn+Ld2OPzJvn+/t4SPZKmLw8nA1/ervyuonCXoFmslWJPV +Fq0kVE2xzcoU0pi8tn1quvuMboUnaI1LFwpMZ6kg2sdsGkmDtwQstl6oMVdn+J1+83Q 3ga15eS2rv0ZLViowOat+ESdioPhqqhw4NG9c8xazQLq6qYFbhvaqWAqm50hG/bck4bZ 1NhLHOmIP+Tb6ideSpSpuwmiXPclV7wYaEw5s06p8nNoJXDXXd5x7pqrQVzFnNoZan3N oyHHdOJUfVqn5VawEnrEaWNgsrbfAJji2vdRBQKF4u6rQg57VENgSoBqTDwaJGyjLNNU PiyA== X-Forwarded-Encrypted: i=1; AJvYcCWExEd6vARrbAALuLbThPC7CorQikIuH0cxXHkngTBuWtTJDjflw+UIYryutbZ1w5jKLY9tOLxHOcjNkDyq@postgresql.org X-Gm-Message-State: AOJu0Yz5D6oaQSND1eWCksOsqOy16XDJHSnpoGPGGt5xrnFksSomBc5v FTxXQUbkeyOP1YZaCIH9fUgUyprQ+gBfQ4FqjxeQnMDQIL2tPXOoKYPxCwyZAw== X-Gm-Gg: ASbGncsU/21HtCueWhiGYc9U4DHBQ9LKaQINnTsbgTlFq1tAiB0gALVAtKK/GHE+8Ts gEqu23nQGxNkLE6CuKpuOK2UA1B3gI2SjwNWewFyhmhijKUSu2BsvXG3DOBlHUYssQIeeazfc88 fAJ/+86Z2naZzLFOhGuaf9NGrJ82Gv1Fm0szuv1eRuYfKuUu9wlg1CLXVtXcQcxfjP85unIPXBQ 82FdqHjo9US9zm5lixphlVws6/2BrAU8nfIxqhaxFMJorVGTMuBwc9/HrBcSsNBab16lYkFTiwa VLnGmFB5GsgPv9UkxqBM4ed0CJY9fapqryiPkNORsi+6sLcQry3eSQBBBAWlhcGpy0NcpgTy+OZ q2BkOx5sHtNlTPV2EFnT2Icuzi64mG8i7Ju76l+xXosTQoA9P1jSBwbI= X-Google-Smtp-Source: AGHT+IGk63jtPJJ/+t0+o8rlf0jbo5UMbpPewt99tCrwidfN+LgpVGccFJpPflxNW89KX+YxFGOPqQ== X-Received: by 2002:a05:6512:a89:b0:553:35ad:2f45 with SMTP id 2adb3069b0e04-553e3cfec05mr1180231e87.50.1750431085533; Fri, 20 Jun 2025 07:51:25 -0700 (PDT) Received: from [192.168.50.231] (broadband-46-242-11-65.ip.moscow.rt.ru. [46.242.11.65]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-553e41c300bsm306311e87.158.2025.06.20.07.51.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Jun 2025 07:51:25 -0700 (PDT) Message-ID: <16f87504-f174-450e-93cc-2db1074522bb@gmail.com> Date: Fri, 20 Jun 2025 17:51:24 +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> Content-Language: ru From: Alexander Borisov In-Reply-To: <4211ffd7fe154c4af693b98d78f4a3689ce8cc30.camel@j-davis.com> 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.06.2025 20:41, Jeff Davis wrote: > On Tue, 2025-06-03 at 00:51 +0300, Alexander Borisov wrote: >> As promised, I continue to improve/speed up Unicode in Postgres. >> Last time, we improved the lower(), upper(), and casefold() >> functions. [1] >> Now it's time for Unicode Normalization Forms, specifically >> the normalize() function. > > Did you compare against other implementations, such as ICU's > normalization functions? There's also a rust crate here: > > https://github.com/unicode-rs/unicode-normalization > > that might have been optimized. I don't quite see how this compares to the implementation on Rust. In the link provided, they use perfect hash, which I get rid of and get a x2 boost. If you take ICU implementations in C++, I have always considered them slow, at least when used in C code. I may well run benchmarks and compare the performance of the approach in Postgres and ICU. But this is beyond the scope of the patches under discussion. I want to emphasize that the pachty I gave doesn't change the normalization code/logic. We change the approach in finding the right codepoints across tables, which is what gives us the performance boost. > In addition to the lookups themselves, there are other opportunities > for optimization as well, such as: > > * reducing the need for palloc and extra buffers, perhaps by using > buffers on the stack for small strings > > * operate more directly on UTF-8 data rather than decoding and re- > encoding the entire string Absolutely agree with you, the normalization code is very well written but far from optimized. I didn't send changes in the normalization code itself to avoid lumping everything together and make the review easier. In keeping with my idea of optimizations in normalization forms, I planned to discuss the optimization code (C code) in the next iteration on “Improve performance...”. -- Regards, Alexander Borisov