Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJj8M-0001yf-4B for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Aug 2022 22:16:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJj8K-00044g-1M for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Aug 2022 22:16:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJj8J-000443-Ml for pgsql-hackers@lists.postgresql.org; Thu, 04 Aug 2022 22:15:59 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oJj8G-0005bF-8E for pgsql-hackers@postgresql.org; Thu, 04 Aug 2022 22:15:58 +0000 Received: by mail-pj1-x1029.google.com with SMTP id w17-20020a17090a8a1100b001f326c73df6so6564739pjn.3 for ; Thu, 04 Aug 2022 15:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=LjN3JPj1s5+rR4uxDijA1wKJ/4mHPGvA/aQTkyY6BQE=; b=oT7qI01w49vUsFLxwXMBriFy7x/B4nt7qOQDb3kJFw+HI4FTSI4Own7xR9BmVFBA2R PQE1OvDLitHGJ1NJBo6hz6fiLPpGtfL5Oo6saUtLXjdYb1LC5XmOOw3uX50igg3W6PLJ e/BRFyJu2Xc3EydlqU4l9U5Wi3zNOW7eax9BzuMO18C5+QLpXLTbjHpW2g8C1UqKSTqz /g6zMF/dnkQYMw423wrp6n9OxX9EsorxvcpVJABnr/76PTa4r6Mcg1iDEXD6EH2lV4RE vmsnPHzC8itPSRZdEYxWdLVdwtvQlJq2v9bTCneGOtHovya4ZWrRyUKC4llu68/nujSH fs0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=LjN3JPj1s5+rR4uxDijA1wKJ/4mHPGvA/aQTkyY6BQE=; b=mSwqF+k/lR4Ng0PdOYGg+RHc55/rAMSd5jjoizfXIZycMqVq8Pn2gcNtOuobRzGjQK 4sjdH1CAbxvbsc068iT74Tg4nDhEvrFp6XAJgC38BTplMJlmdbJ7AM0iVA8jL99ZOQQ1 KR7zw4yQVHBxfNgklmGa4WTVUv21rEsmw61yExig/PJLi3SwrQXAbCV4AdXk9Bzv5WwR 0JrHTcpZF6uO8zPHj/Hz1vfHOYtrZzyWlrJKZXgzDsmP3FrsDRhh5yqs8BJ0i1oxQijo nuZrgY5DhLSuJaHMUyAqLyWygWViZN/PKYgP05J7xqbgfibLw8wdq/sc5xVSAWy7uODR UvdQ== X-Gm-Message-State: ACgBeo05ixt9Jy95AXYbwqKXZbrU3f85dmFk1qm90ZbvRYISHeG8x0FT LPirqD7DHATHzE3AsUJt8lc= X-Google-Smtp-Source: AA6agR7Fbfh+sfd3L9TAt0sg0JXs6sg4zb+rc5NXPfoix4JxZrlfiX6LYzgBgLHUaE+Fs7VLr3JxWA== X-Received: by 2002:a17:90b:1e50:b0:1f5:4f69:d6b8 with SMTP id pi16-20020a17090b1e5000b001f54f69d6b8mr9722778pjb.34.1659651354148; Thu, 04 Aug 2022 15:15:54 -0700 (PDT) Received: from nathanxps13 ([50.216.92.214]) by smtp.gmail.com with ESMTPSA id b3-20020aa79503000000b0052d3899f8c2sm1536242pfp.4.2022.08.04.15.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 15:15:53 -0700 (PDT) Date: Thu, 4 Aug 2022 15:15:51 -0700 From: Nathan Bossart To: John Naylor Cc: Andres Freund , John Naylor , pgsql-hackers Subject: Re: optimize lookups in snapshot [sub]xip arrays Message-ID: <20220804221551.GA1090071@nathanxps13> References: <20220726181906.7l4ulzjdblnanclm@alap3.anarazel.de> <20220728213423.GA408719@nathanxps13> <20220730053811.GA417958@nathanxps13> <20220802221301.GA742739@nathanxps13> <20220802225539.nm7bgkwvkpzgib5x@awork3.anarazel.de> <20220802234357.GA802740@nathanxps13> <20220803180658.3ofq6v34wxchg4wc@awork3.anarazel.de> <20220803202540.GA1088968@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Aug 04, 2022 at 02:58:14PM +0700, John Naylor wrote: > Were you considering adding the new function to simd.h now that that's > committed? It's a bit up in the air what should go in there, but this new > function is low-level and generic enough to be a candidate... I don't have a strong opinion. I went with a separate file because I envisioned a variety of possible linear search functions (e.g., char, uint16, uint32), and some might not use SIMD instructions. Futhermore, it seemed less obvious to look in simd.h for linear search functions. That being said, it might make sense to just add it here for now. > I wonder if the "pg_" prefix is appropriate here, as that is most often > used for things that hide specific details *and* where the base name would > clash, like OS calls or C library functions. I'm not quite sure where the > line is drawn, but I mean that "linearsearch" is a generic algorithm and > not a specific API we are implementing, if that makes sense. Yeah, I was concerned about clashing with lsearch() and lfind(). I will drop the prefix. > The suffix "_uint32" might be more succinct as "32" (cf pg_bswap32(), > pg_popcount32, etc). We'll likely want to search bytes sometime, so > something to keep in mind as far as naming ("_int" vs "_byte"?). How about something like lsearch32 or linearsearch32? > I'm not a fan of "its" as a variable name, and I'm curious what it's > intended to convey. It's short for "iterations." I'll spell it out completely to avoid this kind of confusion. > All the __m128i vars could technically be declared const, although I think > it doesn't matter -- it's just a hint to the reader. Will do. > Out of curiosity do we know how much we get by loading four registers > rather than two? The small program I've been using for testing takes about 40% more time with the two register approach. The majority of this test involves searching for elements that either don't exist in the array or that live near the end of the array, so this is probably close to the worst case. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com