all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: johnw@newartisans.com, emacs-devel@gnu.org
Subject: Re: "concurrency" branch updated
Date: Wed, 4 Nov 2015 04:20:37 -0500	[thread overview]
Message-ID: <FDACCFAE-165A-41BC-A0DB-8EEB1BCB0D29@raeburn.org> (raw)
In-Reply-To: <831tc7vyex.fsf@gnu.org>


> On Nov 3, 2015, at 11:29, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Ken Raeburn <raeburn@raeburn.org>
>> Date: Tue, 3 Nov 2015 04:40:25 -0500
>> Cc: "emacs-devel@gnu.org discussions" <emacs-devel@gnu.org>
>> 
>> At some point, we’ll want to demonstrate practical utility; not a trivial demo program that displays a few messages, and nothing on the scale of rewriting all of Gnus to be multithreaded, but somewhere in between.  I’m not sure what would be a good example.  A version of generator.el that uses threads instead of the CPS transformation of everything is a possibility, and it would probably simplify the writing and compiling of the generators, but it’d probably be more heavy-weight at run time.  Prefetching files’ contents, or searching already-loaded files, while tags-query-replace waits for the user to respond to a prompt?  Improving fontification somehow?
> 
> Given that only one thread can run Lisp, is the above even possible?

Implementing a generator with a thread seems somewhat straightforward, needing some sort of simple communication channel between the main thread and the generator thread to pass “need next value” and “here’s the next value” messages back and forth; some extra work would be needed so that dropping all references to a generator makes everything, including the thread, go away.  Raising an error in the thread’s “yield” calls may be a way to tackle that, though it changes the semantics within the generator a bit.

For prefetching file contents or searching existing buffers, the “main” thread can release the global lock when it prompts for the user’s input, and a background thread can create buffers and load files, or search buffers for patterns, tossing results onto some sort of queue or other data structure for consumption by the main thread when it finishes with the file it’s on.

Inserting a file’s contents or searching a large buffer can take a long time, though, so these could make the interactive experience sluggish at times depending on what’s going on in background, unless we find a way to do some of these operations without holding the global lock.  (Aside: Has anyone thought about applying JIT native code generation or translation-to-C to regular expressions?)  And loading a file can prompt for local variable settings and such, which could get kind of confusing if mixed with tags-query-replace prompting relating to a different file, but refactoring insert-file-contents into a minimal file-reading routine that does no Lisp callbacks and another to deal with file name handlers and hooks and such could let us do the former on a helper thread and the latter (which could prompt the user) in the main thread at the expected time.

Both of those examples are mainly about running some extra work in the moments while we’re waiting for the user to respond to a prompt.  We may be able to do the same with idle timers or other such mechanisms.  In cases like that, I think it may come down to whether it’s easier and/or more maintainable to write code that cranks through the next step of an explicitly managed state machine, or structured code that maintains its state in program counters and variables local to each stack frame… sometimes it’s one, sometimes it’s the other.

As to fontification… I expect the code is pretty tight now, but maybe someone who knows that code has some insight into whether we could do it better with more CPU cores available.

So… yeah, I think some of them are possible, but I’m not sure any of them would be a particularly good way to show off.  Got any suggestions?


> 
>> Understood.  I think there may also be places where we could use threads less visible to the Lisp world; TLS and redisplay come to mind.
> 
> Given the general model-view-controller design of Emacs and the
> structure of its main loop, is making redisplay run in a separate
> thread really viable?

I’m not sure.  I’m not picturing redisplay running concurrently with Lisp so much as redisplay on display 1 running concurrently with redisplay on display 2, all happening at the same point in the code where we now run redisplay.  (Ignoring for the moment the bits where redisplay can trigger Lisp evaluation.)

Under X11 I doubt trying to process different frames on the same display in different threads would help at all, given that the data still all goes through one network connection.  I expect that display updates on Windows, being on the local machine, are fast enough that even if concurrent updates by two or more threads go faster than fully serialized updates, it wouldn’t make much difference in the user experience.  Though I am making some assumptions that redisplay isn’t doing many costly calculations compared to the cost of pushing the bits to the glass.

I suspect TLS is probably the more interesting case.

Ken


  reply	other threads:[~2015-11-04  9:20 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-01  6:19 "concurrency" branch updated Ken Raeburn
2015-11-02 17:09 ` Eli Zaretskii
2015-11-02 20:23 ` John Wiegley
2015-11-02 20:35   ` Eli Zaretskii
2015-11-02 20:41     ` Eli Zaretskii
2015-11-02 21:57       ` John Wiegley
2015-11-03  3:58         ` Elias Mårtenson
2015-11-03  9:40           ` Ken Raeburn
2015-11-03 16:26             ` Eli Zaretskii
2015-11-03 16:23           ` Eli Zaretskii
2015-11-03  9:40   ` Ken Raeburn
2015-11-03 11:50     ` other "concurrency" approaches Nic Ferrier
2015-11-03 15:44       ` Eli Zaretskii
2015-11-03 17:16         ` Nic Ferrier
2015-11-03 17:23           ` Eli Zaretskii
2015-11-03 22:28             ` Nic Ferrier
2015-11-04  3:48               ` Eli Zaretskii
2015-11-03 15:14     ` "concurrency" branch updated Filipp Gunbin
2015-11-03 15:35       ` Michael Albinus
2015-11-03 16:38         ` Thierry Volpiatto
2015-11-03 16:29     ` Eli Zaretskii
2015-11-04  9:20       ` Ken Raeburn [this message]
2015-11-04 15:40         ` Eli Zaretskii
2015-11-04 19:48           ` Ken Raeburn
2015-11-04 20:51             ` Eli Zaretskii
2015-11-05  5:16               ` Ken Raeburn
2015-11-04 23:09         ` Richard Stallman
2015-11-05  3:41           ` Eli Zaretskii
2015-11-05  6:29           ` Ken Raeburn
2015-11-05 13:17             ` John Wiegley
2015-11-05 14:17               ` David Kastrup
2015-11-05 15:07                 ` John Wiegley
2015-11-05 21:55               ` Tom Tromey
2015-11-05 22:01                 ` John Wiegley
2015-11-05 22:46             ` Richard Stallman
2015-11-06  8:37               ` Eli Zaretskii
2015-11-05 21:49           ` Tom Tromey
2015-11-05 21:46         ` Tom Tromey
2015-11-06  7:58           ` Eli Zaretskii
2015-11-06 14:58             ` Tom Tromey

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=FDACCFAE-165A-41BC-A0DB-8EEB1BCB0D29@raeburn.org \
    --to=raeburn@raeburn.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=johnw@newartisans.com \
    /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.