Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBYEN-0008KX-JM for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 05:14:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBYEL-0002Jx-2L for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 05:14:33 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBYEK-0002Jq-Mn for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 05:14:32 +0000 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBYEH-0002Hk-SW for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 05:14:32 +0000 Received: by mail-pg1-x535.google.com with SMTP id v12so7711146pgq.1 for ; Tue, 02 Apr 2019 22:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=zI8wtmvCUQJibKyMQHTILr/be3SseXsc+lD+n3LqpkA=; b=chvMVkjEYE46J0MA3vdgjrFu1oB6yoej3vPj9s9FjvJCAA2tYyEBnPfJ8K3UI4FuRS y5tQwD6KHAaVReH92z+tIlMkgjXGX42Qatla833NhUHV2QWPZzRiUuZGnAWr+fMcHE7l ZtrYCvaqkFEOpiuinSd45aWZotr3jXZbay+zLiG6Uw2HI74UPSoTWTGLJZtsmrymriJs bpOXPIgKJj/IPQ+U7tE0kqqBkKsZ6uqkBeMf5Sv5LkK/76x/770OYEsN4OPgwYcPupky 9pEzSt8uwyBMF728Hhg3YHmxcVG1P9GK1aF4XwsnN0fW6o3pTw6UppFWYZkmgY6ZMom4 uPXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=zI8wtmvCUQJibKyMQHTILr/be3SseXsc+lD+n3LqpkA=; b=LZuJrdwg7lEMXVXoOVGM97hTWjUkglBfHUVikwx1gQK+WpVUnbGNF4pYsMY0O3rRGj jTZjX3ivYZxF93Lj46+bdMoYG18TYPvrMpIJlDIwtMx27rEaUS/hQYW0pMOONQ+jrqc7 Yqtiawct3FYqfhE+UFw8VA9uERKOg+11vLubKyXNuGYbeixKQQoi1rk6vEyX98znrqcl 9YpzBKamb98DbqnJGMdk7VH86WI15SnryPI9xAoMZNHMWKPFFw31mXjCZvGmmpNb7tyf FgmEF4PKqfJo7C9d3K6HqH6Tjnfeyy9/m+hIDJXS/HV6EFDKubd6y+veAWJB7YFOaqrL SZKA== X-Gm-Message-State: APjAAAWjFvGFhiH1jq6ur262yeqDLI+si9+9fIxMGn7Jt3KDIeX+r/ok K4kwZqs6OWTYbMjz6C+gL2ZCtv7Gji8= X-Google-Smtp-Source: APXvYqxcv0lFUHacGScQh2rwtODkkJ9DqyiccAl7eAzGUC+/oDk7A+eCJ3qS6aJSjoqrqe1CzQ8c3A== X-Received: by 2002:a63:ff66:: with SMTP id s38mr68587975pgk.120.1554268467152; Tue, 02 Apr 2019 22:14:27 -0700 (PDT) Received: from [192.168.43.209] ([42.109.147.53]) by smtp.gmail.com with ESMTPSA id s20sm5091340pgs.39.2019.04.02.22.14.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 22:14:26 -0700 (PDT) Subject: Re: New LLVM JIT Features To: Andres Freund Cc: pgsql-general@lists.postgresql.org References: <20190402215021.q7e7xjmobakkgan5@alap3.anarazel.de> From: preejackie Message-ID: <859aa673-8303-2a1b-cc23-0dadfd412ec1@gmail.com> Date: Wed, 3 Apr 2019 10:44:06 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190402215021.q7e7xjmobakkgan5@alap3.anarazel.de> Content-Type: multipart/alternative; boundary="------------857CC8DC9FE32CFEF378F902" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------857CC8DC9FE32CFEF378F902 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Andres, Thanks for the reply! Please see my comments inline. On 03/04/19 3:20 AM, Andres Freund wrote: > Hi, > > On 2019-04-02 00:51:51 +0530, preejackie wrote: >> As LLVM ORC supports compiling in multiple backend threads, it would be >> effective if we compile the functions speculatively before they are called >> by the executing function. So when we request JIT to compile a function, JIT >> will immediately returns the function address for raw executable bits. This >> will greatly reduce the JIT latencies in modern multi-core machines. > I personally think this should be approached somewhat differently - > putting patchpoints into code reduces the efficiency of the generated > code, so I don't think that's the right approach. What I think we should  What do you mean by patch points here? To my knowledge, LLVM symbols have arbitrary stub associated which resolve to function address at function address. > do is to, if we decide it's worthwhile at plan time, generate the LLVM > IR time at the beginning of execution, but continue to use interpreted > execution initially. The generated IR would then be handed over to a > background [process|thread|whatnot] for optimization of code > generation. Then, when finished, I'd switch over from interpreted to JIT > compiled execution. That approach will, in my view, yield better > latency behaviour because we can actually evaluate quals etc for which > we've not yet finished code generation. > > >> And also I'm working on designing a ORC in-place dynamic profiling support, by >> this JIT will automatically able to identify the hot functions, and compile >> it in higher optimization level to achieve good performance. > I think that's a nice concept, but at the moment the generated code is > so bad that it's much more likely to get big benefits by improving the > generated IR, compared to giving more hints to the optimizer. By improving the generated IR, you mean by turning pgsql queries into LLVM IR? If it is the case, this design doesn't handles that, it works only when the given program representation is in LLVM IR. > > Greetings, > > Andres Freund -- Have a great day! PreeJackie --------------857CC8DC9FE32CFEF378F902 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Andres,

Thanks for the reply! Please see my comments inline.

On 03/04/19 3:20 AM, Andres Freund wrote:
Hi,

On 2019-04-02 00:51:51 +0530, preejackie wrote:
As LLVM ORC supports compiling in multiple backend threads, it would be
effective if we compile the functions speculatively before they are called
by the executing function. So when we request JIT to compile a function, JIT
will immediately returns the function address for raw executable bits. This
will greatly reduce the JIT latencies in modern multi-core machines.
I personally think this should be approached somewhat differently -
putting patchpoints into code reduces the efficiency of the generated
code, so I don't think that's the right approach. What I think we should
 What do you mean by patch points here? To my knowledge, LLVM symbols have arbitrary stub associated which resolve to function address at function address.
do is to, if we decide it's worthwhile at plan time, generate the LLVM
IR time at the beginning of execution, but continue to use interpreted
execution initially. The generated IR would then be handed over to a
background [process|thread|whatnot] for optimization of code
generation. Then, when finished, I'd switch over from interpreted to JIT
compiled execution.  That approach will, in my view, yield better
latency behaviour because we can actually evaluate quals etc for which
we've not yet finished code generation.


And also I'm working on designing a ORC in-place dynamic profiling support, by
this JIT will automatically able to identify the hot functions, and compile
it in higher optimization level to achieve good performance.
I think that's a nice concept, but at the moment the generated code is
so bad that it's much more likely to get big benefits by improving the
generated IR, compared to giving more hints to the optimizer.
By improving the generated IR, you mean by turning pgsql queries into LLVM IR? If it is the case, this design doesn't handles that, it works only when the given program representation is in LLVM IR. 

Greetings,

Andres Freund
-- 
Have a great day!
PreeJackie
--------------857CC8DC9FE32CFEF378F902--