From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Inefficiency in Bgotoifnil byte-code instruction Date: Thu, 28 Jun 2012 00:38:10 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1340858302 24336 80.91.229.3 (28 Jun 2012 04:38:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 28 Jun 2012 04:38:22 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 28 06:38:22 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sk6Ul-0000Jn-01 for ged-emacs-devel@m.gmane.org; Thu, 28 Jun 2012 06:38:19 +0200 Original-Received: from localhost ([::1]:38402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sk6Ul-0003a5-0F for ged-emacs-devel@m.gmane.org; Thu, 28 Jun 2012 00:38:19 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sk6Uh-0003Zy-MY for emacs-devel@gnu.org; Thu, 28 Jun 2012 00:38:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sk6Uf-0004Vs-Of for emacs-devel@gnu.org; Thu, 28 Jun 2012 00:38:15 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:62600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sk6Uf-0004VB-KN for emacs-devel@gnu.org; Thu, 28 Jun 2012 00:38:13 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09soXbe/2dsb2JhbABEtBGBCIIVAQEEAVYoCws0EhQYDYhABboJjSaDHgOjM4FYgwU X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="192248337" Original-Received: from 108-161-118-222.dsl.teksavvy.com (HELO pastel.home) ([108.161.118.222]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 28 Jun 2012 00:38:10 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 75E28592B0; Thu, 28 Jun 2012 00:38:10 -0400 (EDT) In-Reply-To: (John Wiegley's message of "Wed, 27 Jun 2012 22:01:52 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151252 Archived-At: > My recommendation is that we split these into two ops: Bgotoifnil and > Bgotoifnonnil, which use only FETCH and a positive/negative offset from the > current pc, and Bgotoifnil2 and Bgotoifnonnil2 which use the old logic > (FETCH2, and an absolute offset from the start of the bytecode stream). You mean, provide "short" forms of Bgotoifnil and Bgotoifnonnil? I'm not sure it's worth the trouble: the only benefit is to replace a FETCH2 by a FETCH, which doesn't seem like it would save a large fraction of the time to execute those operations. Of course, when it comes to performance, intuition is often wrong, so feel free to try it out. > Making this change in the C code is easy, but changing bytecomp.el wasn't > obvious to me. Can anyone help me with that? You want to look at byte-compile-lapcode, where: (cond ((memq op byte-goto-ops) ;; goto (byte-compile-push-bytecodes opcode nil (cdr off) bytes pc) (push bytes patchlist)) is the code that outputs the 3 bytes (opcode, nil, and (cdr off)), where the last 2 are not real bytes yet (they'll be filled later via `patchlist'). So you can probably get what you want by only changing: (dolist (bytes-tail patchlist) (setq pc (caar bytes-tail)) ; Pick PC from goto's tag. (setcar (cdr bytes-tail) (logand pc 255)) (setcar bytes-tail (lsh pc -8)) ;; FIXME: Replace this by some workaround. (if (> (car bytes-tail) 255) (error "Bytecode overflow"))) such that if the `pc' (which is the target address) is sufficiently close to the current address (which the current code doesn't compute currently but which should be (length bytes-tail), IIRC), then change the opcode, use setcdr to drop a byte, and set the offset byte. Of course, since that will change the offsets of subsequent code, you might prefer to traverse patchlist in the reverse order and keep a counter of dropped bytes, and you'll have to change (setq pc (caar bytes-tail)) to something like (setq pc (- (caar bytes-tail) dropped-bytes)). I hope that makes sense to you, Stefan