From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Raeburn Newsgroups: gmane.lisp.guile.devel Subject: Re: guile performance - Ackermann function: way slower than emacs, slower still if compiled Date: Thu, 6 Aug 2009 03:31:51 -0400 Message-ID: <6203BF4F-1F11-46F7-9F4A-55D83E3CA205@raeburn.org> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v935.3) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1249543942 31696 80.91.229.12 (6 Aug 2009 07:32:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Aug 2009 07:32:22 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Aug 06 09:32:15 2009 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MYxSQ-0002Xa-Dd for guile-devel@m.gmane.org; Thu, 06 Aug 2009 09:32:15 +0200 Original-Received: from localhost ([127.0.0.1]:58636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MYxSP-00017k-KB for guile-devel@m.gmane.org; Thu, 06 Aug 2009 03:32:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MYxSM-00017f-3U for guile-devel@gnu.org; Thu, 06 Aug 2009 03:32:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MYxSH-00017P-E3 for guile-devel@gnu.org; Thu, 06 Aug 2009 03:32:09 -0400 Original-Received: from [199.232.76.173] (port=54967 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MYxSH-00017L-9e for guile-devel@gnu.org; Thu, 06 Aug 2009 03:32:05 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:42197) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MYxSG-0004YI-Br for guile-devel@gnu.org; Thu, 06 Aug 2009 03:32:04 -0400 Original-Received: from splat.raeburn.org ([69.25.196.39] helo=raeburn.org) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MYxS7-0000ce-Nr for guile-devel@gnu.org; Thu, 06 Aug 2009 03:32:03 -0400 Original-Received: from [10.0.0.172] (squish.raeburn.org [10.0.0.172]) by raeburn.org (8.14.3/8.14.1) with ESMTP id n767Vp01022569; Thu, 6 Aug 2009 03:31:51 -0400 (EDT) In-Reply-To: X-Mailer: Apple Mail (2.935.3) X-Detected-Operating-System: by mx20.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9034 Archived-At: 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