Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZgGBc-0000tf-Is for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Sep 2015 17:56:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZgGBb-0002Zw-HM for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Sep 2015 17:56:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZgGBa-0002Zp-Qm for pgsql-hackers@postgresql.org; Sun, 27 Sep 2015 17:56:30 +0000 Received: from smtp-auth.no-ip.com ([8.23.224.61] helo=out.smtp-auth.no-ip.com) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZgGBQ-0005Lc-AB for pgsql-hackers@postgresql.org; Sun, 27 Sep 2015 17:56:29 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [186.11.242.182]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 249BC400BCC; Sun, 27 Sep 2015 10:56:12 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 296DF219A; Sun, 27 Sep 2015 14:56:08 -0300 (CLT) Date: Sun, 27 Sep 2015 14:56:08 -0300 From: Alvaro Herrera To: Jinyu Zhang Cc: "pgsql-hackers@postgresql.org" Subject: Re: Patch: Optimize memory allocation in function 'bringetbitmap' Message-ID: <20150927175608.GM295765@alvherre.pgsql> References: <495deb78.4186.1500dacaa63.Coremail.beijing_pg@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <495deb78.4186.1500dacaa63.Coremail.beijing_pg@163.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Jinyu Zhang wrote: > > BRIN Scan: Optimize memory allocation in function 'bringetbitmap'. > We can allocate memory for some pointer before do long loop instead of allocating > memory in long loop. > > Before optimizing code (warm run) > postgres=# select count(*) from lineitem where l_orderkey=1; > Time: 456.219 ms > > After optimizing code (warm run) > postgres=# select count(*) from lineitem where l_orderkey=1; > Time: 349.219 ms Hmm, did you measure this in a c-assert-enabled build? Those are slower in allocation because of the memory-clobber thingy; without that, the allocations would be a lot faster, so perhaps the gains are not so interesting. Still, it's a lot of palloc/pfree calls that do not happen with your patch, so perhaps it's still worthwhile, but please do measure it. However I wonder if it would be simpler to have the dtup structure have the pointers, so that you can pass it as NULL in the first call and then followup calls reuse the one allocated in the first call. That makes the callers a bit less ugly, I think. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers