From: Eli Zaretskii <eliz@gnu.org>
To: sbaugh@catern.com
Cc: emacs-devel@gnu.org
Subject: Re: Releasing the thread global_lock from the module API
Date: Sun, 03 Mar 2024 17:51:46 +0200 [thread overview]
Message-ID: <86cysbnwj1.fsf@gnu.org> (raw)
In-Reply-To: <87cysbjvw7.fsf@catern.com> (sbaugh@catern.com)
> From: sbaugh@catern.com
> Date: Sun, 03 Mar 2024 13:19:04 +0000
>
> Eli Zaretskii <eliz@gnu.org> writes:
> >
> > A module whose call takes this little time to complete and whose calls
> > from Lisp are so massive should not, and need not, use this technique,
> > because releasing the global lock for such a short time will not
> > benefit anything. Releasing a global lock is only beneficial if a
> > module call does a lot of work, during which other Lisp threads could
> > do something useful. but if a module call takes a significant time
> > (say, a few seconds), then adding a 20 usecs to that time is
> > insignificant.
>
> Yes, to avoid the thread creation overhead, a native module should only
> create a native thread to run some_native_function if the native module
> knows that some_native_function will take a long time.
>
> Unfortunately, most of the time a native module can't know how long
> some_native_function will take before calling it. For example, native
> functions which make network calls might return immediately when there's
> already data available from the network, but will have to send new
> network requests sometimes. Or, native functions which provide an
> in-memory database might be fast or slow depending on the database
> contents.
I believe the cases where it is not known in advance whether a module
call can take only a few tens or hundreds of microseconds or longer
are very rare. And if the timing depends on some internally
maintained data, such as the size of a DB, the decision can even be
made dynamically, at least in some cases (although I'd consider that a
premature optimization).
> Since the native module doesn't know if some_native_function will take a
> long time
I think in most cases it can and does know. In general, only rare
module calls will take such a long time that releasing the lock will
be justified. Module calls that are fast enough shouldn't bother.
> > Sorry, I don't agree to adding such interfaces to Emacs. And if you
> > are still not convinced, let's agree to disagree.
>
> That is understandable, but I think you are not yet appreciating that
> this can be a very useful way to introduce parallelism with high
> performance.
I think I do appreciate the odds. More importantly, I have a lot of
gray hair from fixing various problems with our threads. I also don't
believe Emacs is a platform suitable for high-performance parallelism.
> Is there anything that would convince you of such things?
Unlikely. Maybe a complete redesign of how threads are switched in
Emacs. I don't think you have any idea how fragile the machinery we
have now really is.
next prev parent reply other threads:[~2024-03-03 15:51 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 14:53 Releasing the thread global_lock from the module API Spencer Baugh
2024-03-01 16:47 ` Eli Zaretskii
2024-03-01 17:34 ` Spencer Baugh
2024-03-01 18:44 ` Eli Zaretskii
2024-03-01 19:02 ` Spencer Baugh
2024-03-01 19:26 ` Eli Zaretskii
2024-03-01 19:51 ` Spencer Baugh
2024-03-01 20:42 ` Eli Zaretskii
2024-03-01 21:21 ` Spencer Baugh
2024-03-01 21:34 ` Eli Zaretskii
2024-03-01 21:56 ` Spencer Baugh
2024-03-02 6:43 ` Eli Zaretskii
2024-03-02 16:39 ` sbaugh
2024-03-02 17:02 ` Eli Zaretskii
2024-03-02 20:33 ` Spencer Baugh
2024-03-03 6:13 ` Eli Zaretskii
2024-03-03 13:19 ` sbaugh
2024-03-03 15:42 ` Dmitry Gutov
2024-03-03 15:51 ` Eli Zaretskii [this message]
2024-03-01 19:30 ` tomas
2024-03-01 23:53 ` Dmitry Gutov
2024-03-02 5:57 ` tomas
2024-03-02 15:35 ` Dmitry Gutov
2024-03-02 16:31 ` tomas
2024-03-02 21:41 ` sbaugh
2024-03-03 6:25 ` tomas
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86cysbnwj1.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=sbaugh@catern.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 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).