unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Is byte-compiled code supposed to call `make-byte-code'?
@ 2016-05-24 20:58 Paul Pogonyshev
  2016-05-24 21:19 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Pogonyshev @ 2016-05-24 20:58 UTC (permalink / raw
  To: emacs-devel

Trying to disassemble a trivial function that invokes a closure:

(defun xxx (fn)
  (mapcar (lambda (x) (1+ (funcall fn x))) '(1 2 3)))
(disassemble 'xxx)

gives:

0       constant  mapcar
1       constant  make-byte-code
2       constant  257
3       constant  "\300\x01!T\207"
4       constant  vconcat
5       constant  vector
6       stack-ref 6
8       call      1
9       constant  []
10      call      2
11      constant  3
12      constant  "\n\n(fn X)"
13      call      5
14      constant  (1 2 3)
15      call      2
16      return

Is it supposed to build closure bytecode object every time? Shouldn't
it be considered a constant?

GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.20.3) of 2016-05-24

Paul



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Is byte-compiled code supposed to call `make-byte-code'?
  2016-05-24 20:58 Is byte-compiled code supposed to call `make-byte-code'? Paul Pogonyshev
@ 2016-05-24 21:19 ` Andreas Schwab
  2016-05-25  8:53   ` Paul Pogonyshev
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2016-05-24 21:19 UTC (permalink / raw
  To: Paul Pogonyshev; +Cc: emacs-devel

Paul Pogonyshev <pogonyshev@gmail.com> writes:

> Is it supposed to build closure bytecode object every time? Shouldn't
> it be considered a constant?

But it isn't a constant, it depends on the function's argument.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Is byte-compiled code supposed to call `make-byte-code'?
  2016-05-24 21:19 ` Andreas Schwab
@ 2016-05-25  8:53   ` Paul Pogonyshev
  2016-05-25 14:13     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Pogonyshev @ 2016-05-25  8:53 UTC (permalink / raw
  To: Andreas Schwab; +Cc: emacs-devel

Andreas Schwab wrote:
> But it isn't a constant, it depends on the function's argument.

You are right, didn't think about it. However, given that it is a
repetetive process, shouldn't all constant parts of it be moved to C
level instead of bytecode, as an optimization? E.g. add (make-closure
descriptor &rest constants), where descriptor would include the actual
bytecode, arglist, depth and constants inherited from outer closure?
Then `xxx' would disassemble to something like

0       constant  mapcar
1       constant  make-closure
2       constant  <<descriptor>>
3       stack-ref <<fn>>
5       call      2
6       constant  (1 2 3)
7       call      2
9       return

Thus, bytecode size would decrease for closure-heavy code and speed
likely improve as well.

Paul



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Is byte-compiled code supposed to call `make-byte-code'?
  2016-05-25  8:53   ` Paul Pogonyshev
@ 2016-05-25 14:13     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2016-05-25 14:13 UTC (permalink / raw
  To: emacs-devel

>> But it isn't a constant, it depends on the function's argument.
> You are right, didn't think about it. However, given that it is a
> repetetive process, shouldn't all constant parts of it be moved to C
> level instead of bytecode, as an optimization?

When Emacs-24.1 introduced lexical-binding, the focus was on:
- preserving backward compatibility.
- minimizing the amount of code changed.
- providing correct semantics.
- no speed regression.

IOW performance of lexically scoped code was not on the agenda.

Notice that the problem in the code you quote is not just the amount of
byte-code, but also in the closure that's generated: whether we hide it
inside a new "make-closure" bytecode or not, the construction of the new
closure object is more costly than in most "standard" representation
of closures (which normally only involves construction of one object,
rather than two).

So, yes, there's a fair bit of room for improvement (and not just in
this one particular spot).


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-25 14:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-24 20:58 Is byte-compiled code supposed to call `make-byte-code'? Paul Pogonyshev
2016-05-24 21:19 ` Andreas Schwab
2016-05-25  8:53   ` Paul Pogonyshev
2016-05-25 14:13     ` Stefan Monnier

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).