unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: Inefficiency in Bgotoifnil byte-code instruction
Date: Thu, 28 Jun 2012 00:38:10 -0400	[thread overview]
Message-ID: <jwvpq8k2hz4.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <m2ehp0nnq7.fsf@newartisans.com> (John Wiegley's message of "Wed,  27 Jun 2012 22:01:52 -0500")

> 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



  reply	other threads:[~2012-06-28  4:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-28  3:01 Inefficiency in Bgotoifnil byte-code instruction John Wiegley
2012-06-28  4:38 ` Stefan Monnier [this message]
2012-06-29 16:39   ` Tom Tromey
2012-06-30  4:07     ` Stefan Monnier
2012-07-02 19:17       ` Tom Tromey
2012-07-03 13:19         ` Stefan Monnier
2012-07-03 14:45           ` Tom Tromey
2012-07-03 16:58             ` Stefan Monnier
2012-07-03 17:22               ` Tom Tromey
2012-07-03 17:53                 ` Aurélien Aptel
2012-07-03 19:24                   ` Tom Tromey
2012-07-03 23:02                 ` Stefan Monnier
2012-07-06 20:22                   ` Tom Tromey
2012-07-06 21:39                     ` Stefan Monnier
2012-07-09 19:12                   ` Tom Tromey
2012-07-10 10:31                     ` Stefan Monnier
2012-07-03 19:52             ` John Wiegley
2012-07-06 20:27           ` Tom Tromey
2012-07-02  3:51     ` John Wiegley
2012-07-02 14:08       ` Tom Tromey
2012-06-28  4:41 ` Stefan Monnier
2012-06-28 13:07 ` Richard Stallman
2012-06-28 21:24   ` John Wiegley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvpq8k2hz4.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).