From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Robert Thorpe Newsgroups: gmane.emacs.help Subject: Re: Optimising Elisp code [again] Date: Fri, 12 Oct 2018 20:52:36 +0100 Message-ID: <87va67aqnv.fsf@robertthorpeconsulting.com> References: <86bm80l5g6.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1539373876 7517 195.159.176.226 (12 Oct 2018 19:51:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 12 Oct 2018 19:51:16 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 12 21:51:12 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gB3Sp-0001oy-Tk for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Oct 2018 21:51:12 +0200 Original-Received: from localhost ([::1]:42412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gB3Uw-00048A-Cr for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Oct 2018 15:53:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gB3UJ-000484-JX for help-gnu-emacs@gnu.org; Fri, 12 Oct 2018 15:52:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gB3UG-00061U-CX for help-gnu-emacs@gnu.org; Fri, 12 Oct 2018 15:52:43 -0400 Original-Received: from outbound-smtp13.blacknight.com ([46.22.139.230]:33230) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gB3UG-0005zo-1h for help-gnu-emacs@gnu.org; Fri, 12 Oct 2018 15:52:40 -0400 Original-Received: from mail.blacknight.com (unknown [81.17.255.152]) by outbound-smtp13.blacknight.com (Postfix) with ESMTPS id 63D3E1C2D8B for ; Fri, 12 Oct 2018 20:52:37 +0100 (IST) Original-Received: (qmail 23179 invoked from network); 12 Oct 2018 19:52:37 -0000 Original-Received: from unknown (HELO RTLaptop) (rt@robertthorpeconsulting.com@[51.37.99.2]) by 81.17.254.9 with ESMTPSA (AES128-SHA encrypted, authenticated); 12 Oct 2018 19:52:37 -0000 In-Reply-To: <86bm80l5g6.fsf@zoho.com> (message from Emanuel Berg on Thu, 11 Oct 2018 20:10:49 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.22.139.230 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118256 Archived-At: Emanuel Berg writes: > =C3=93scar Fuentes wrote: > >>> The Elisp interpreter is probably tightly >>> intertwined with the Emacs editor code. >>> Disentangling them so you can compile Elisp >>> to machine code would be a big project, and >>> probably not worth it. >> >> http://git.savannah.gnu.org/cgit/emacs.git/log/?h=3Dfeature/libjit >> >> https://github.com/tromey/el-compilador > > Wonderful! But how does one integrate the > compiled code with the rest of Emacs? Firstly, I think it's worth clarifying how things work now. Emacs has two interpreters. There's the interactive interpreter, that's what's run when you type elisp straight into Emacs. It is used to interpret files ending in ".el". Then there's the bytecode interpreter. To use that you have to compile a program to bytecode first. It's the bytecode interpreter that deals with ".elc" files. The bytecode interpreter is much faster than the interactive interpreter. (I expect you know all this Emanuel, I'm just writing it here for others who are reading who might not). The libjit branch works by compiling bytecode into native code. As I understand it, this is done at runtime, so the user doesn't have to do anything. I think there was another project that did something similar at compile time. Compiling bytecode sounds a bit strange, but it makes sense. In many cases what the JIT does is emit the same code that is inside the bytecode interpreter. In a very simplified sense, it works like this.... So, the bytecode interpreter is a big switch/case statement. Somewhere there is instruction FOO. When the JIT compiler sees FOO it inserts into it's output buffer the code that was in the bytecoding interpreter to deal with that opcode. There are some optimizations beyond that. I think it's a good idea and I hope it will be merged into mainline Emacs one day. BR, Robert Thorpe