unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
To: guile-devel <guile-devel@gnu.org>
Subject: Re: guile performance - Ackermann function: way slower than emacs, slower still if compiled
Date: Thu, 6 Aug 2009 03:31:51 -0400	[thread overview]
Message-ID: <6203BF4F-1F11-46F7-9F4A-55D83E3CA205@raeburn.org> (raw)
In-Reply-To: <D92A3A2A-395E-4A2B-9D12-694D42CDE1D3@raeburn.org>

On Aug 5, 2009, at 10:06, Ken Raeburn wrote:
> (1) In scm_pthread_mutex_lock, we leave and re-enter guile mode so  
> that we don't block the thread while in guile mode.  But we could  
> use pthread_mutex_trylock first, and avoid the costs scm_leave_guile  
> seems to incur on the Mac.  If we can't acquire the lock, it should  
> return immediately, and then we can do the expensive, blocking  
> version.  A quick, hack version of this changed my run time for  
> A(3,8) from 17.5s to 14.5s, saving about 17%; sigaltstack and  
> sigprocmask are still in the picture, because they're called from  
> scm_catch_with_pre_unwind_handler.  I'll work up a nicer patch later.

Ah, we already had scm_i_pthread_mutex_trylock lying around; that made  
things easy.
A second timing test with A(3,9) and this version of the patch (based  
on 1.9.1) shows the same improvement.

diff --git a/libguile/threads.c b/libguile/threads.c
index 9589336..8458a60 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -1826,10 +1826,15 @@ scm_std_select (int nfds,
  int
  scm_pthread_mutex_lock (scm_i_pthread_mutex_t *mutex)
  {
-  scm_t_guile_ticket t = scm_leave_guile ();
-  int res = scm_i_pthread_mutex_lock (mutex);
-  scm_enter_guile (t);
-  return res;
+  if (scm_i_pthread_mutex_trylock (mutex) == 0)
+    return 0;
+  else
+    {
+      scm_t_guile_ticket t = scm_leave_guile ();
+      int res = scm_i_pthread_mutex_lock (mutex);
+      scm_enter_guile (t);
+      return res;
+    }
  }

  static void





  reply	other threads:[~2009-08-06  7:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-04  9:28 guile performance - Ackermann function: way slower than emacs, slower still if compiled Ken Raeburn
2009-08-04 13:52 ` Marijn Schouten (hkBst)
2009-08-04 15:56   ` Ken Raeburn
2009-08-05  9:06 ` Andy Wingo
2009-08-05 14:06   ` Ken Raeburn
2009-08-06  7:31     ` Ken Raeburn [this message]
2009-08-26 22:39       ` Neil Jerram
2009-08-06 16:30     ` entering and leaving guile mode, and GC stack protection (was Re: guile performance - Ackermann function: way slower than emacs, slower still if compiled) Ken Raeburn
2009-08-12 22:06       ` entering and leaving guile mode, and GC stack protection Andy Wingo
2009-08-14  7:58         ` Ludovic Courtès
2009-08-08 21:52   ` guile performance - Ackermann function: way slower than emacs, slower still if compiled Ludovic Courtès
2009-08-12 22:28     ` Andy Wingo
2009-08-05 10:42 ` Andy Wingo
2009-08-06 15:59   ` Andy Wingo
2009-08-07 17:27     ` Andy Wingo
2009-08-05 11:15 ` Andy Wingo

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/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6203BF4F-1F11-46F7-9F4A-55D83E3CA205@raeburn.org \
    --to=raeburn@raeburn.org \
    --cc=guile-devel@gnu.org \
    /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.
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).