From: Eli Zaretskii <eliz@gnu.org>
To: Spencer Baugh <sbaugh@catern.com>
Cc: sbaugh@janestreet.com, emacs-devel@gnu.org
Subject: Re: Releasing the thread global_lock from the module API
Date: Sun, 03 Mar 2024 08:13:06 +0200 [thread overview]
Message-ID: <864jdnq1vx.fsf@gnu.org> (raw)
In-Reply-To: <87le70jrwr.fsf@catern.com> (message from Spencer Baugh on Sat, 02 Mar 2024 20:33:05 +0000 (UTC))
> From: Spencer Baugh <sbaugh@catern.com>
> Date: Sat, 02 Mar 2024 20:33:05 +0000 (UTC)
> Cc: sbaugh@janestreet.com, emacs-devel@gnu.org
>
> >> So, the main difference between the "new thread" model and the "release
> >> lock" model is that creating a native thread takes a nontrivial amount
> >> of time; maybe around 0.1 milliseconds. If some_native_function would
> >> takes less time than that, the thread creation cost will slow down
> >> Emacs, especially because the native module creates the native thread
> >> while holding the Lisp global_lock.
> >
> > Why are you worried by 0.1 msec slowdown (if it indeed takes that
> > long; I think it should be around 10 to 20 usec at most)? If this
> > kind of slowdown is important for you, you are using the wrong
> > software package (and probably the wrong OS as well).
>
> Because a Lisp program that uses a native module might make thousands of
> module calls. This is fine when each call takes a microsecond. If we
> add, for example, 500 microseconds of overhead to each module call, then
> 1000 module calls will take half a second.
>
> For example: I have a project.el backend which uses a native module.
> Looking up the project for the current directory and then getting the
> name of the project makes around 5 module calls. I have around 200
> projects. That works out to 1000 module calls to get the names of all
> my projects. Currently with the native module backend this takes around
> a millisecond. With 500 extra microseconds per call, it will take half
> a second.
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.
> >> The "release lock" model fits this need.
> >
> > But it exposes the sensitive internals and runs the risk of more than
> > one Lisp thread running at the same time, and thus is not acceptable.
>
> Yes. But of course in practice we would find a design which allows
> releasing the lock but is hard to misuse.
Sorry, I don't believe this is reliably possible, or safe enough to
justify exposing the lock to Lisp. Certainly not to modules, which is
an open-ended gateway into the bowels of the Emacs Lisp machine.
> How about this:
>
> native_output = env->call_without_lock(some_native_function, native_input);
>
> call_without_lock would be a function which releases the global lock,
> calls a specified function, then acquires the global lock again.
Sorry, I don't agree to adding such interfaces to Emacs. And if you
are still not convinced, let's agree to disagree.
next prev parent reply other threads:[~2024-03-03 6:13 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 [this message]
2024-03-03 13:19 ` sbaugh
2024-03-03 15:42 ` Dmitry Gutov
2024-03-03 15:51 ` Eli Zaretskii
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=864jdnq1vx.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=sbaugh@catern.com \
--cc=sbaugh@janestreet.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).