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 1rrwFw-003ha3-Eh for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Apr 2024 08:46:05 +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 1rrwFv-00GuRD-B2 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Apr 2024 08:46:03 +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 1rrwFu-00GuP9-QT for pgsql-hackers@lists.postgresql.org; Wed, 03 Apr 2024 08:46:03 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rrwFr-000ORx-Hr for pgsql-hackers@lists.postgresql.org; Wed, 03 Apr 2024 08:46:01 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6e6b22af648so568031b3a.0 for ; Wed, 03 Apr 2024 01:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1712133957; x=1712738757; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=cnAAG5w/vUkiAnUFt6W5/D3E/rkKxQ1uquSjZJ1eojw=; b=BZtRXpTRHtM5ydwxmLZCs+2NlNt4HUizb8W9QAxBOg/hISgHsJADMerufyKdTBkGJG 9oSL+EfHwO+G2dbbIsSaqpaG+9hujiiG21a3BrZsMPh9vBxyItyoS1md+PCdoPrHZGd4 FHFluV7vHqISLhoDyHTWk5PYbMQj132XhVfN+rhyECCIFvpE9UoUA9mA8iSMfsjgtuaZ 6cnrgW+lzg5JZA9oT4u+bCR/Rf4/psuiFZ1XvdLh+t+7yRSmv4c/c7MsbmAeBZEXLahd ad7DnLO8avhVGbbYTCN0DjE/d2IOx6c0kpO647PndY4ZRxMbZBVZnKzf3QSrG9jZ2Gmz 4JOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712133957; x=1712738757; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cnAAG5w/vUkiAnUFt6W5/D3E/rkKxQ1uquSjZJ1eojw=; b=mSAHNRSzbka5AEzbJx/xRjzawR2emVSQfk9iSy4tsXpbW7WTq1vap42ak42g5x6dYU KXl1EJfOSNLzEEzkltQSgw/7mQZiCeL+/Q/7CjhnFwi2tpKT/304ZxjLhx0O3jLbv+RU EP/gfH77RyuaW6maKvMSCNT9kdE+RE5p13E9tuWyU6X7WkKba3ZBbHVmkFJWHvYuHgDk n3OhukSBRKJ0ZA5ronqPqgp4B5L8uX+NJfo0kKNYUOq8UDtB08wleYuxh9ZvxmA8rzpg VEE5beSekOjE3fens2YAQ0ZXIV42UOxo9Zikyc/QsMELMLKMppJ6JimSVQIh92P1KOdO r7NQ== X-Forwarded-Encrypted: i=1; AJvYcCV67KDjkCbpPHaZRQOccWxg5LKiUasa5aPsVUNKbvx9m93LanMU5F68MWJLcFCOhfrYHLk1e8JCN53gHuc2HubU15c60pOvmFpatGuovp/zdkXe X-Gm-Message-State: AOJu0YxejWYYPLxvPJDBci1R9gE8FTFBSrtBEff2kqKvQ2AOp49K0QBl h+6217rqXSAlFtC//HaWIXj9GacCn5cbu/QJyxdO32Nf9EhDZn3SQK4VCfz9OA== X-Google-Smtp-Source: AGHT+IG5X7YkpdlNWp9tCnx1nGqFJNq/s3bm+z33bjpE8Ifik8l8p3CSI5R6wOQStLBFQyXMQhV34Q== X-Received: by 2002:a05:6a20:430c:b0:1a7:2437:2230 with SMTP id h12-20020a056a20430c00b001a724372230mr2288425pzk.19.1712133957516; Wed, 03 Apr 2024 01:45:57 -0700 (PDT) Received: from jeff-laptop.lan (c-76-102-242-158.hsd1.ca.comcast.net. [76.102.242.158]) by smtp.gmail.com with ESMTPSA id ey12-20020a056a0038cc00b006eaaaf5e0a8sm11252198pfb.71.2024.04.03.01.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:45:57 -0700 (PDT) Message-ID: <12747c15811d94efcc5cda72d6b35c80d7bf3443.camel@j-davis.com> Subject: Re: Improve eviction algorithm in ReorderBuffer From: Jeff Davis To: Masahiko Sawada , Amit Kapila Cc: vignesh C , Peter Smith , Tomas Vondra , "Hayato Kuroda (Fujitsu)" , Shubham Khanna , Dilip Kumar , PostgreSQL Hackers Date: Wed, 03 Apr 2024 01:45:55 -0700 In-Reply-To: References: <23e03725-8c77-431d-9f53-51709260ffeb@enterprisedb.com> <787cd90b-48ff-4c4a-a63e-a2b3f494385d@enterprisedb.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2024-04-01 at 12:42 +0900, Masahiko Sawada wrote: > While reviewing the patches, I realized the comment of > binearyheap_allocate() should also be updated. So I've attached the > new patches. In sift_{up|down}, each loop iteration calls set_node(), and each call to set_node does a hash lookup. I didn't measure it, but that feels wasteful. I don't even think you really need the hash table. The key to the hash table is a pointer, so it's not really doing anything that couldn't be done more efficiently by just following the pointer. I suggest that you add a "heap_index" field to ReorderBufferTXN that would point to the index into the heap's array (the same as bh_nodeidx_entry.index in your patch). Each time an element moves within the heap array, just follow the pointer to the ReorderBufferTXN object and update the heap_index -- no hash lookup required. That's not easy to do with the current binaryheap API. But a binary heap is not a terribly complex structure, so you can just do an inline implementation of it where sift_{up|down} know to update the heap_index field of the ReorderBufferTXN. Regards, Jeff Davis