all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Elisp containers
Date: Fri, 07 Sep 2018 14:13:53 -0600	[thread overview]
Message-ID: <871sa5xdz2.fsf@tromey.com> (raw)
In-Reply-To: <jwvr2i5iee1.fsf-monnier+gmane.emacs.devel@gnu.org> (Stefan Monnier's message of "Fri, 07 Sep 2018 10:38:18 -0400")

>>>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

Stefan> If someone feels like they have too much time on their hands, I think
Stefan> a great feature to develop would be Elisp containers.

Stefan> This would be like running Elisp in a separate process, except that it's
Stefan> not a separate process, so communication between two containers can be
Stefan> very efficient (e.g. you can send a buffer from one container to the
Stefan> other as efficiently as you can send an integer).

I considered this when working on threads.  I thought I'd write to
discuss the problems I had with it; not to discourage anybody, but in
case somebody has thoughts on how to improve things.

I think the basic idea is to avoid data races while also avoiding the
overhead of a separate process.  So the design should keep things in
process (duh) and also reject shared mutable state; instead objects must
be explicitly sent between threads.  (If you lift this latter
requirement then you really just have what we have now.)


So, first, what environment should a new thread inherit?

If it is a clean environment -- say a copy of the dumped state -- then
that means that user changes won't affect threads.  And, threading code
will need to know exactly what things must be copied into the new
container.

This seemed unfortunate to me, not to mention hard on thread users,
because it's difficult in an open environment to know what may be
required.  (You can see echoes of this problem in the mhtml mode, where
it has to use a regexp on symbol names, eww, to capture locals.)

However, if it is not a clean environment, then thread creation will be
very expensive.  You will have to copy much of the heap into the new
thread.  (Perhaps the copying could be done lazily at the expense of
slowing down access to global variables.)


Second, sending a large object to another thread will also be slow.  The
buffer *itself* is not too bad, but buffers have properties and
buffer-local bindings, and these must all be deep copied.

One idea I had to reduce the cost here was to have a special case: when
a thread dies, let thread-join simply transfer the data from that thread
to its own heap.


Finally, this approach greatly reduces debuggability and the ability to
mess around.  Emacs would no longer be an open system -- threads would
have private data and there would be no way to access that.

Tom



  parent reply	other threads:[~2018-09-07 20:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-07 14:38 Elisp containers Stefan Monnier
2018-09-07 17:54 ` John Wiegley
2018-09-07 18:08   ` Stefan Monnier
2018-09-07 18:25     ` John Wiegley
2018-09-07 18:04 ` Eric Abrahamsen
2018-09-07 20:13 ` Tom Tromey [this message]
2018-09-08 19:25   ` Vladimir Sedach
2018-09-09 18:53     ` Tom Tromey
2018-09-08  5:14 ` Richard Stallman
2018-09-08  5:45 ` Helmut Eller
2018-09-08 17:56   ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=871sa5xdz2.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.