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 1sSIfN-0063FF-Sl for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jul 2024 15:58:37 +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 1sSIfM-009gAN-GD for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jul 2024 15:58:36 +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 1sSIfM-009gAE-3e for pgsql-hackers@lists.postgresql.org; Fri, 12 Jul 2024 15:58:36 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sSIfJ-001iv8-JE for pgsql-hackers@lists.postgresql.org; Fri, 12 Jul 2024 15:58:34 +0000 Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-8036ce66164so76374939f.3 for ; Fri, 12 Jul 2024 08:58:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720799912; x=1721404712; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=RCP5XxYO1diHZuF2KmAv/Eaouem1og9iX8k9Wgq35Co=; b=PpVhTWPuhHSR/4HEetjqKnA5s912CnipQZBkQrTf5kW0eVyZKywtsutQVydgyddsa7 8ovulSYE8wkINpamN8dPRPDNFR441BMiB6DIrwUABqNFY17KSZqC6fxFXz7z6t4EVIl/ cBB5XLiAPOJ8XDK/T2Me9shwI117vZqegRMAGwWdrBzTyMpFbd4TVrG496OtQFkC8Gov FKBYfq77tGHYhjVvijjfdEeZj/JZpq3ez3tohzL8wsxElOXNaB3ekj+hYhN8n/gGwwlZ 938i7NAbQ17ZkS0KLMdAHtFdkk4vCt+j8qsLNDuPUZKwU6rP4gzuR9voBzsxPv9hBQBU tBYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720799912; x=1721404712; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RCP5XxYO1diHZuF2KmAv/Eaouem1og9iX8k9Wgq35Co=; b=P8I4IITWFUbGyXt4TZ/+ptwUpHUZ0TwgH8hmJwZ8UG+0A5OpDqlYtDYcwK2ThlCT/N y4zJrlZQ24+lHiwiNp+qR8hO7h26Jy+lRZ/III8+DGDJFKDK+n3l+OAZj4i3eOKbnrqi cAfVzSXmRkkDaaomeUcYBoyak9njvKsP0UGdHpGZFOMokhneAqj5wLA+Jeb0OGpD3rS4 RCS6/V5UqE/qRtJ5TTsGUDjSsMX1OD7IE5N4UfY5sNp+1tNcWvKRQI5zqBtvE2Y5nM+i iAwArqkzI/jStQWZYpTUO7v9msTy7kiT371YB0kByClZOOBBJBHM0c/yVRsqbyBVO7Wc tgMg== X-Gm-Message-State: AOJu0YynsYP9pOXO7xbq5y9Gk9aYuw8llzas0/S0Y5t009Qa+FvAPqoz uHvxxEnve1dLaREYEi8LyuFSzo9p6ixEoJ5B90MxdyqlLPHnO2jF X-Google-Smtp-Source: AGHT+IHlGyPEqf72WQo8fhJqvbR0XLa+X9tJeybpTwN8JkPfGB+3DSO9gm8J/CFBZHeac1gdsJiuAg== X-Received: by 2002:a05:6602:712:b0:803:980e:5b38 with SMTP id ca18e2360f4ac-803980e5e1emr937392239f.1.1720799912331; Fri, 12 Jul 2024 08:58:32 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c0b1b5c62csm2523539173.80.2024.07.12.08.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 08:58:31 -0700 (PDT) Date: Fri, 12 Jul 2024 10:58:30 -0500 From: Nathan Bossart To: Antonin Houska Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Missed opportunity for bsearch() in TransactionIdIsCurrentTransactionId()? Message-ID: References: <36977.1720623613@antos> <47366.1720778471@antos> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47366.1720778471@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jul 12, 2024 at 12:01:11PM +0200, Antonin Houska wrote: > Nathan Bossart wrote: >> My concern with switching them to bsearch() would be the performance impact >> of using a function pointer for the comparisons. Perhaps we could add a >> couple of inlined binary search implementations for common types to replace >> many of the open-coded ones. > > bsearch() appears to be used widely, but o.k., I don't insist on using it to > replace the existing open-coded searches. Sorry, I didn't mean to say that I was totally against switching to bsearch(), but I do think we need to understand whether there is any performance impact before doing so, especially in hot paths. It would be nice if we could reduce the number of open-coded binary searches in some fashion, and if we can maintain or improve performance by creating a handful of static inline functions, that would be even better. If there's no apparent performance difference, bsearch() is probably fine. -- nathan