GNU bug report logs - #42028
[Feature Request] 27.0.91; Provide the ability dynamic modules to post events in emacs event loop

Previous Next

Package: emacs;

Reported by: Ivan Yonchovski <yyoncho <at> gmail.com>

Date: Wed, 24 Jun 2020 07:15:01 UTC

Severity: wishlist

To reply to this bug, email your comments to 42028 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 07:15:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ivan Yonchovski <yyoncho <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 24 Jun 2020 07:15:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ivan Yonchovski <yyoncho <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [Feature Request] 27.0.91; Provide the ability dynamic modules to
 post events in emacs event loop
Date: Wed, 24 Jun 2020 10:14:44 +0300

This is needed for the cases when the module is listening for extenal
events and wants to call back emacs to process them. ATM this is kind of
possible by using signals on linux and using WM_INPUTLANGCHANGE as
described in https://nullprogram.com/blog/2017/02/14/ but this looks
more a hack for a missing feature.







Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 14:46:01 GMT) Full text and rfc822 format available.

Message #8 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ivan Yonchovski <yyoncho <at> gmail.com>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91;
 Provide the ability dynamic modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 17:44:42 +0300
> From: Ivan Yonchovski <yyoncho <at> gmail.com>
> Date: Wed, 24 Jun 2020 10:14:44 +0300
> 
> This is needed for the cases when the module is listening for extenal
> events and wants to call back emacs to process them. ATM this is kind of
> possible by using signals on linux and using WM_INPUTLANGCHANGE as
> described in https://nullprogram.com/blog/2017/02/14/ but this looks
> more a hack for a missing feature.

It is almost trivial to let modules insert events into the event
queue.  The problem is that I expect a module that inserts such events
to want to be called to process those events as well.  Is that
expectation correct?  If it is, then we need to think about extending
the mechanism that calls event handlers, not just about exposing the
likes of kbd_buffer_store_event to modules.  We should also consider
how a module could define its own events.

IOW, this calls for a slightly more detailed specification, before
someone could sit down and code the stuff.  I suggest to take a look
at how existing events are handled, and propose such a detailed
specification.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 16:18:02 GMT) Full text and rfc822 format available.

Message #11 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: yyoncho <yyoncho <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91; Provide the ability dynamic
 modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 19:17:30 +0300
[Message part 1 (text/plain, inline)]
> The problem is that I expect a module that inserts such events
> to want to be called to process those events as well.  Is that
> expectation correct?
>

Yes. As a side note, this feature will be useful even for the core C part
for anything
that wants to perform async processing not including LispObject.

Thanks,
Ivan
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 16:30:02 GMT) Full text and rfc822 format available.

Message #14 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: yyoncho <yyoncho <at> gmail.com>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91; Provide the ability dynamic
 modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 19:28:54 +0300
> From: yyoncho <yyoncho <at> gmail.com>
> Date: Wed, 24 Jun 2020 19:17:30 +0300
> Cc: 42028 <at> debbugs.gnu.org
> 
> As a side note, this feature will be useful even for the core C part for anything
> that wants to perform async processing not including LispObject. 

How will it help that?  The event queue is processed synchronously.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 16:48:01 GMT) Full text and rfc822 format available.

Message #17 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: yyoncho <yyoncho <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91; Provide the ability dynamic
 modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 19:46:56 +0300
[Message part 1 (text/plain, inline)]
Here it is an example: If we oversimplify json parsing consist of 2 parts.

1. JSON parsing to Jansson data structures
2. Converting Jasson data structures to lisp data structures.

If we assume that 1 is taking most of the time then we could write the
following code:

start(string, callback) -> convert string to char* -> post it to worker
thread -> worker thread does the parsing
-> worker thread post to main loop -> main loop converts Jansson ds to lisp
ds -> main loop
calls the callback passed on start

The same strategy probably could be applied to Font locking with
TreeSitter.

Thanks,
Ivan

On Wed, Jun 24, 2020 at 7:29 PM Eli Zaretskii <eliz <at> gnu.org> wrote:

> > From: yyoncho <yyoncho <at> gmail.com>
> > Date: Wed, 24 Jun 2020 19:17:30 +0300
> > Cc: 42028 <at> debbugs.gnu.org
> >
> > As a side note, this feature will be useful even for the core C part for
> anything
> > that wants to perform async processing not including LispObject.
>
> How will it help that?  The event queue is processed synchronously.
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 17:09:02 GMT) Full text and rfc822 format available.

Message #20 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: yyoncho <yyoncho <at> gmail.com>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91; Provide the ability dynamic
 modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 20:07:50 +0300
> From: yyoncho <yyoncho <at> gmail.com>
> Date: Wed, 24 Jun 2020 19:46:56 +0300
> Cc: 42028 <at> debbugs.gnu.org
> 
> 1. JSON parsing to Jansson data structures
> 2. Converting Jasson data structures to lisp data structures.
> 
> If we assume that 1 is taking most of the time

Does it?  Did someone time these separately?

> start(string, callback) -> convert string to char* -> post it to worker thread -> worker thread does the parsing
> -> worker thread post to main loop -> main loop converts Jansson ds to lisp ds -> main loop
> calls the callback passed on start

You cannot easily post to the queue from a worker thread, because the
queue cannot be posted to asynchronously.

And I lack the larger picture: how would this work within a framework
of some Emacs feature?  E.g., how will this processed be triggered,
and by what kind of trigger?

> The same strategy probably could be applied to Font locking with TreeSitter. 

Again, I don't see the wider picture.  Are you familiar with how the
current JIT font-lock works?  If so, can you explain which parts of
that will be replaced/modified, and how?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 17:34:01 GMT) Full text and rfc822 format available.

Message #23 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: Ivan Yonchovski <yyoncho <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91; Provide the ability
 dynamic modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 20:33:29 +0300
Eli Zaretskii writes:

> Does it?  Did someone time these separately?

IDK, this was just an example.

>> start(string, callback) -> convert string to char* -> post it to worker thread -> worker thread does the parsing
>> -> worker thread post to main loop -> main loop converts Jansson ds to lisp ds -> main loop
>> calls the callback passed on start
>
> You cannot easily post to the queue from a worker thread, because the
> queue cannot be posted to asynchronously.

AFAIK this is not possible at all - thus this feature request.

>
> And I lack the larger picture: how would this work within a framework
> of some Emacs feature?  E.g., how will this processed be triggered,
> and by what kind of trigger?

The goal users to be able to handle more usecases. ATM the only way to
achieve that is hackish as described here
https://nullprogram.com/blog/2017/02/14/ + several practical usecases.


> Again, I don't see the wider picture.  Are you familiar with how the
> current JIT font-lock works?  If so, can you explain which parts of
> that will be replaced/modified, and how?

AFAIK the initial tree-sitter parsing (which does not involve anything
emacs related) may take 200-300ms. In other editors (e.g. vscode) this
part is not happening on the UI thread but in some extenal background
thread which then passes the AST to the main UI thread to do the actual
fontlock. IMO this model might be replicated in emacs in the event of TS
integration.

Thanks,
Ivan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 18:06:01 GMT) Full text and rfc822 format available.

Message #26 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ivan Yonchovski <yyoncho <at> gmail.com>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91; Provide the ability
 dynamic modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 21:04:52 +0300
> From: Ivan Yonchovski <yyoncho <at> gmail.com>
> Cc: 42028 <at> debbugs.gnu.org
> Date: Wed, 24 Jun 2020 20:33:29 +0300
> 
> > You cannot easily post to the queue from a worker thread, because the
> > queue cannot be posted to asynchronously.
> 
> AFAIK this is not possible at all - thus this feature request.

Your feature just asked for a way to queue events, it didn't say
anything about doing that asynchronously, not from a function invoked
by the main thread.  If you mean the latter, then it AFAIU would need
a serious redesign of the Emacs event queue, to make it accessible
from several threads running in parallel at once.

> > Again, I don't see the wider picture.  Are you familiar with how the
> > current JIT font-lock works?  If so, can you explain which parts of
> > that will be replaced/modified, and how?
> 
> AFAIK the initial tree-sitter parsing (which does not involve anything
> emacs related) may take 200-300ms. In other editors (e.g. vscode) this
> part is not happening on the UI thread but in some extenal background
> thread which then passes the AST to the main UI thread to do the actual
> fontlock. IMO this model might be replicated in emacs in the event of TS
> integration.

What you describe is very different from how JIT font-lock works now.
Which is why I asked the question: I know (more or less) how it works
in other editors, I just don't yet understand well enough how
something like that would fit into the existing fontification
framework.  I hope there is a way of fitting it, because otherwise it
would mean a serious surgery of the display engine as well, which will
make the job significantly larger and harder.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42028; Package emacs. (Wed, 24 Jun 2020 18:39:01 GMT) Full text and rfc822 format available.

Message #29 received at 42028 <at> debbugs.gnu.org (full text, mbox):

From: Ivan Yonchovski <yyoncho <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 42028 <at> debbugs.gnu.org
Subject: Re: bug#42028: [Feature Request] 27.0.91; Provide the ability
 dynamic modules to post events in emacs event loop
Date: Wed, 24 Jun 2020 21:38:31 +0300
Eli Zaretskii writes:

>
> Your feature just asked for a way to queue events, it didn't say
> anything about doing that asynchronously, not from a function invoked
> by the main thread.  If you mean the latter, then it AFAIU would need
> a serious redesign of the Emacs event queue, to make it accessible
> from several threads running in parallel at once.

Yes, sorry about that. I didn't mention it explicitly in the bug report
it was described in more details in the linked article.

> What you describe is very different from how JIT font-lock works now.
> Which is why I asked the question: I know (more or less) how it works
> in other editors, I just don't yet understand well enough how
> something like that would fit into the existing fontification
> framework.  I hope there is a way of fitting it, because otherwise it
> would mean a serious surgery of the display engine as well, which will
> make the job significantly larger and harder.

IMO we are good here. At least on lsp-mode side we were able to
implement delayed semantic fontification as a result of async source.
But in lsp-mode case we are reseiving the messages from the server on
the UI thread.

Thanks,
Ivan




This bug report was last modified 3 years and 307 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.