[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Inefficiency in Bgotoifnil byte-code instruction
From: |
Stefan Monnier |
Subject: |
Re: Inefficiency in Bgotoifnil byte-code instruction |
Date: |
Thu, 28 Jun 2012 00:38:10 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) |
> 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