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 1oJ1YT-0001c0-Ql for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2022 23:44:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJ1YS-0006Vo-0c for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2022 23:44:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJ1YR-0006Vf-ME for pgsql-hackers@lists.postgresql.org; Tue, 02 Aug 2022 23:44:03 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oJ1YO-0002lY-C7 for pgsql-hackers@postgresql.org; Tue, 02 Aug 2022 23:44:02 +0000 Received: by mail-pf1-x436.google.com with SMTP id f28so6740720pfk.1 for ; Tue, 02 Aug 2022 16:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tyEck5BTHk4cliF6LBEEX/2ksD3WIr5isO6hnI3cN6w=; b=kDq4crv3cyeUD3vP49bRx+srIsn3qjXrE+u249TWwBg4GoSXcOieCN5H/KoGeU6OZr LgCGii4yeoKw3Z6QpvwZFXXj/e+SKJaVfKW075adWyh5GnMRr07BkudA5NP++KUxkFnP YKojwIgL50bCpBB5qd4Dtxh0Xp6iT7u0hD0hggl3k3oOYSjl0njUosOAl6VQURMuPjt+ 9ZsL9tfYmYuzdkwci1GMkcmf7C1T2Q+0kZ42PeKAteqt2zD1icmsTiU+PUI1mmYLv9ap Brzp28KfA0o3nE9rV2m8ecsAwIpgsfJ3M8cNgT33cBC4qHCr0Okxwxr/6zjPHB/4eBGK 5hCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tyEck5BTHk4cliF6LBEEX/2ksD3WIr5isO6hnI3cN6w=; b=Wihu30SUy6xHfsxxpt47iU67Ad6GjVQ0WSN2QQWGH9hsZtVa0/xKpLkzJqJA0zLM8+ IZgPjHGy2qXlyAaiSoPK4uaZzZHCsIa7R0P5RKpS3fBUy5NXwVDHGf53R0eWljDzB+GD 2tY9/juvqWktZg+lfgW0C4T3+8tlVQKRqy//jCNSND7ukGHrS8wAQJS3cW4L5tk+uQiH ffHsJ8CFBg/typNulzCVI6VE7DAHEGAwoVAy1J7HOgh7+i9J/tUoGuW5hBspFj5NrKXy wpdVjpOTA/Ll3mk5YHzeJI7TW7Q2sne2hG9RGFRSL41F1DS8Yzt4OOrpAC9qKTGmk9eS jx+w== X-Gm-Message-State: ACgBeo1VEGmqO0+Ze/NofBWjwpG8glt+Ff4Rc1qs/K0L7SWenDPI1dnG nxel3Ss0llnWPBEElj2THEc= X-Google-Smtp-Source: AA6agR74cqTA9Ciig3Kp8Ql0PKQsc8jJanoX52iLTNEBkSRhWzoBntJgB/847Fb7fk9v8kZgSesMuw== X-Received: by 2002:a63:693:0:b0:41b:aa71:7a56 with SMTP id 141-20020a630693000000b0041baa717a56mr16137073pgg.427.1659483839207; Tue, 02 Aug 2022 16:43:59 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id s2-20020a625e02000000b005251c6fbd0csm11453369pfb.29.2022.08.02.16.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 16:43:58 -0700 (PDT) Date: Tue, 2 Aug 2022 16:43:57 -0700 From: Nathan Bossart To: Andres Freund Cc: John Naylor , John Naylor , pgsql-hackers Subject: Re: optimize lookups in snapshot [sub]xip arrays Message-ID: <20220802234357.GA802740@nathanxps13> References: <20220713170950.GA3116318@nathanxps13> <20220715200857.nm2gc4weixwlwbnx@awork3.anarazel.de> <20220717035957.GA3631071@nathanxps13> <20220725190419.GA4095199@nathanxps13> <20220726181906.7l4ulzjdblnanclm@alap3.anarazel.de> <20220728213423.GA408719@nathanxps13> <20220730053811.GA417958@nathanxps13> <20220802221301.GA742739@nathanxps13> <20220802225539.nm7bgkwvkpzgib5x@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220802225539.nm7bgkwvkpzgib5x@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Aug 02, 2022 at 03:55:39PM -0700, Andres Freund wrote: > FWIW, I'd split the introduction of the helper and the use of it in snapmgr > into separate patches. Will do. > On 2022-08-02 15:13:01 -0700, Nathan Bossart wrote: >> diff --git a/src/include/c.h b/src/include/c.h >> index d35405f191..2c1a47bc28 100644 >> --- a/src/include/c.h >> +++ b/src/include/c.h >> @@ -371,6 +371,14 @@ typedef void (*pg_funcptr_t) (void); >> #endif >> #endif >> >> +/* >> + * Are SSE2 intrinsics available? >> + */ >> +#if (defined(__x86_64__) || defined(_M_AMD64)) >> +#include >> +#define USE_SSE2 >> +#endif >> + > > It doesn't strike me as a good idea to include this in every single > translation unit in pg. That header (+dependencies) isn't small. > > I'm on board with normalizing defines for SSE availability somewhere central > though. Yeah, this is just a temporary hack for now. It'll go away once the defines for SSE2 availability are committed. >> +/* >> + * pg_linearsearch_uint32 >> + * >> + * Returns the address of the first element in 'base' that equals 'key', or >> + * NULL if no match is found. >> + */ >> +#ifdef USE_SSE2 >> +pg_attribute_no_sanitize_alignment() >> +#endif > > What's the deal with this annotation? Needs a comment. Will do. c.h suggests that this should only be used for x86-specific code. >> +static inline uint32 * >> +pg_linearsearch_uint32(uint32 key, uint32 *base, uint32 nelem) > > Hm. I suspect this could be a bit faster if we didn't search for the offset, > but just for presence in the array? Most users don't need the offset. Just under half of the callers in 0002 require the offset, but I don't know if any of those are worth optimizing in the first place. I'll change it for now. It's easy enough to add it back in the future if required. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com