emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Releasing the thread global_lock from the module API


From: Eli Zaretskii
Subject: Re: Releasing the thread global_lock from the module API
Date: Sun, 03 Mar 2024 17:51:46 +0200

> 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]