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 1tdF3a-005qpL-8C for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jan 2025 20:53:06 +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 1tdF3Z-008pCS-4N for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jan 2025 20:53:05 +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 1tdF3Y-008pCK-RA for pgsql-hackers@lists.postgresql.org; Wed, 29 Jan 2025 20:53:04 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tdF3W-002Ea8-04 for pgsql-hackers@postgresql.org; Wed, 29 Jan 2025 20:53:04 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-540218726d5so71203e87.2 for ; Wed, 29 Jan 2025 12:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738183981; x=1738788781; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=/okO0DH7RYUUw5GSOryFOQLkLW2/Pc3v2V86cw0RQSE=; b=lfhxliA5JI12nzDI1RfXaIgUQWudxsdwGtOBLtajGNPPpa/EgOj9Ol3vTgb3BuLiec h3uVMygr7hzj/+ZcUjs/iIu1gC7jUMFLGUbAeuFQGkHRc3jsxr9Ai+jw+L0GtiN1Xva7 xXs75ZdemvAuu9pjxJMeiwLO2skwv8boR2KO18L9T+Cum3eEHqWJTPYPbW6LTfpqiVem O2NAJgw4epHor2Jc07UNEBcyF8j6kCez7OJ6EhGXMh/riER9ZobtCCuJ/Upn4QNICqbV r0J3ySltFww6jncLwp/FmwtNB9hZhoZcxhMiPLZupFcmgn5ScWtKdk+ZsPMWNUJ1Ejk5 SypQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738183981; x=1738788781; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/okO0DH7RYUUw5GSOryFOQLkLW2/Pc3v2V86cw0RQSE=; b=FW+uXe6ax+CCRU4jkUSrE89RtTIJYEKGghp9ywrT64XD1ZYsuM+NeUYnAyUI3iUIoG HTbQlnECTCwaSyWpMukJvjQLj2Rs9cuxBuo+TiTHOPF8/iGT11BLziin2qtJqmQKZPph HlcQj9ZieRSCqowT1bM81YLM49sDhUIzjJvftClxvu9pqGIaubB+zOXVIHe0UE4k8kBr cnUZbDJ2kVcia3RQyea5VPDxgKDODdR1+SSD3uS9/brDm4ThVBXWcQ9szIcRWorcuobf TnM12ji0tiO7+BxRcoZbS6zwswXjcdCXjfsYAUaO/XuWimpsw4gf85O5MEOqCmcFGHa+ Nexg== X-Gm-Message-State: AOJu0YyHOcCC2jyktdvL3WfNBrrjOl5lZPZdvBkugtsOuLXoJjYAlmiL 3YZqJU4MgVIcM8kyauz07d8N1TabTkYodFgQRoLXfmNK7vOA7lNJp9mr1w== X-Gm-Gg: ASbGncs+2mZaYuqh2SLRjAvCQUaM/cQpgRDIBJMwDKWG+Ea7ltDPlvkXbzscc/GaWMe C+vV+AYYqYZU5VCbxPbUm0j7tNcglWicKM6H5sreUw0WOtbqAz/znys8L0vp0CgIw5eObmqSZm6 KYY+dqyxIGqgAI7Ra1v191DMiEQMlBqngtTwXJUynTIRZSF9xXzqlSGt8G6JgtCv8Zbo2n8fEzU gpIKELH9+tBkb+Z0EozZilmtybh9pydCfp2ZSvkOsETkjmTtntR6LAf9iqkzR5uQ78M9Sos5Rau FgQOgbqj0jG5wNTyEgXe9rotQ8fEksW7k+zB0DBCyzhNA0a4QhIUQaO6YNgEMuv4r9dTxacWVaM yGv0b6ynQ X-Google-Smtp-Source: AGHT+IEsPq2+5zO0+lzvRx9ez1haJjoLEE5trrmlhF/HmqT3BlYBZrzIflaQxyQTOfIpsJMA8opURw== X-Received: by 2002:ac2:55ab:0:b0:540:2549:b5ad with SMTP id 2adb3069b0e04-543e4beab7dmr1266516e87.22.1738183980604; Wed, 29 Jan 2025 12:53:00 -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-543c836832bsm2053877e87.158.2025.01.29.12.53.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 12:53:00 -0800 (PST) Message-ID: <2a1b632e-4531-43cf-a6d9-51cc1a271dc1@gmail.com> Date: Wed, 29 Jan 2025 23:52:59 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Optimization for lower(), upper(), casefold() functions. From: Alexander Borisov To: pgsql-hackers@postgresql.org References: <7cac7e66-9a3b-4e3f-a997-42aa0c401f80@gmail.com> Content-Language: ru In-Reply-To: <7cac7e66-9a3b-4e3f-a997-42aa0c401f80@gmail.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 Sorry, I made a mistake in the code. It's not worth watching this patch yet. 29.01.2025 23:23, Alexander Borisov пишет: > Hi, hackers! > > I propose to consider a simple optimization for Unicode case tables. > The main changes affect the generate-unicode_case_table.pl file. > > Because of the modified approach of record search by table we > managed to: > 1. Removed storing Unicode codepoints (unsigned int) in all tables. > 2. Reduce the main table from 3003 to 1575 (duplicates removed) records. > 3. Replace pointer (essentially uint64_t) with uin8_t in the main table. > 4. Reduced the time to find a record in the table. > 5. Reduce the size of the final object file. > > The approach is generally as follows: > Group Unicode codepoints into ranges in which the difference between > neighboring elements does not exceed the specified limit. > For example, if there are numbers 1, 2, 3, 5, 6 and limit = 1, then > there is a difference of 2 between 3 and 5, which is greater than 1, > so there will be ranges 1-3 and 5-6. > > Then we form a table (let's call it an index table) by combining the > obtained ranges. The table contains uint16_t index to the main table. > > Then from the previously obtained diapasons we form a function > (get_case()) to get the index to the main table. The function, in fact, > contains only IF/ELSE IF constructs imitating binary search. > > Because we are not directly accessing the main table with data, we can > exclude duplicates from it, and there are almost half of them. > Also, because get_case() contains all the information about Unicode > ranges, we don't need to store Unicode codepoints in the main table. > Also because of this approach some checks were removed, which allowed > to increase performance even with fast path (codepoints < 0x80). > > casefold() test. > > * macOS 15.1 (Apple M3 Pro) (Apple clang version 16.0.0) > > ASCII: > Repeated characters (700kb) in the range from 0x20 to 0x7E. > Patch: tps = 282.457745 > Without: tps = 263.749652 > > Cyrillic: > Repeated characters (1MB) in the range from 0x0410 to 0x042F. > Patch: tps = 82.399637 > Without: tps = 48.291034 > > Unicode: > A query consisting of all Unicode characters from 0xA0 to 0x2FA1D > (excluding 0xD800..0xDFFF). > Patch: tps = 120.703471 > Without: tps = 92.423490 > > * Ubuntu 24.04.1 (Intel(R) Xeon(R) Gold 6140) (gcc version 13.3.0) > > ASCII: > Repeated characters (700kb) in the range from 0x20 to 0x7E. > Patch: tps = 172.291972 > Without: tps = 111.592281 > > Cyrillic: > Repeated characters (1MB) in the range from 0x0410 to 0x042F. > Patch: tps = 36.487650 > Without: tps = 22.537515 > > Unicode: > A query consisting of all Unicode characters from 0xA0 to 0x2FA1D > (excluding 0xD800..0xDFFF). > Patch: tps = 55.190635 > Without: tps = 45.493104 > > -- Alexander Borisov