From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matthias Koeppe Newsgroups: gmane.lisp.guile.devel Subject: Patch for speeding up the debugging evaluator by a factor of 600 Date: Thu, 08 Jul 2004 21:37:19 +0200 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1089315482 2517 80.91.224.253 (8 Jul 2004 19:38:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 8 Jul 2004 19:38:02 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Jul 08 21:37:54 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BieiQ-0005W7-00 for ; Thu, 08 Jul 2004 21:37:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BiekY-00030c-3V for guile-devel@m.gmane.org; Thu, 08 Jul 2004 15:40:06 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BiekS-000304-KF for guile-devel@gnu.org; Thu, 08 Jul 2004 15:40:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BiekR-0002za-2K for guile-devel@gnu.org; Thu, 08 Jul 2004 15:40:00 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BiekQ-0002zP-T5 for guile-devel@gnu.org; Thu, 08 Jul 2004 15:39:58 -0400 Original-Received: from [141.44.75.40] (helo=merkur.math.uni-magdeburg.de) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Biehw-0000Eg-FZ for guile-devel@gnu.org; Thu, 08 Jul 2004 15:37:24 -0400 Original-Received: from gamma ([141.44.75.90] helo=gamma.math.uni-magdeburg.de) by merkur.math.uni-magdeburg.de with esmtp (Exim 4.10) id 1Biehs-00029d-00 for guile-devel@gnu.org; Thu, 08 Jul 2004 21:37:20 +0200 Original-Received: (from mkoeppe@localhost) by gamma.math.uni-magdeburg.de (8.12.9+Sun/8.12.9/Submit) id i68JbJ4U022788; Thu, 8 Jul 2004 21:37:19 +0200 (MEST) X-Authentication-Warning: gamma.math.uni-magdeburg.de: mkoeppe set sender to mkoeppe@mail.math.uni-magdeburg.de using -f Original-To: guile-devel@gnu.org User-Agent: Gnus/5.110001 (No Gnus v0.1) Emacs/21.3.50 (usg-unix-v) 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: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3844 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3844 I am using Guile 1.6.4 with GOOPS and about 4000 primitive procedures. In this setting, when I try to TRACE a function, the debugging evaluator becomes unusably slow. I illustrate this on a call to APROPOS: guile> (time (apropos "doesntexist")) ;; Evaluation took: ;; 0.05 seconds of real time ;; 0.04 seconds of user time ;; 0 seconds of system time guile> (trace load) $3 = (load-module) guile> (time (apropos "doesntexist")) ;; Evaluation took: ;; 32.02 seconds of real time ;; 32.02 seconds of user time ;; 0 seconds of system time I found out that a one-line change by Mikael Djurfeldt in CVS HEAD makes a major speed-up: 2003-03-06 Mikael Djurfeldt * procprop.c (scm_stand_in_scm_proc): Use scm_assq instead of scm_assoc. --- procprop.c.~1.37.2.2.~ 2002-03-21 17:53:18.000000000 +0100 +++ procprop.c 2004-07-08 19:43:16.746126000 +0200 @@ -160,7 +160,7 @@ scm_stand_in_scm_proc(SCM proc) { SCM answer; - answer = scm_assoc (proc, scm_stand_in_procs); + answer = scm_assq (proc, scm_stand_in_procs); if (SCM_FALSEP (answer)) { answer = scm_closure (scm_list_2 (SCM_EOL, SCM_BOOL_F), SCM_EOL); With this change applied to branch_release_1_6, I get: guile> (trace load) $3 = (load-module) guile> (time (apropos "doesntexist")) ;; Evaluation took: ;; 1.17 seconds of real time ;; 1.17 seconds of user time ;; 0 seconds of system time A 30-fold speedup, but still much slower than the untraced version. The scm_assq is still the bottleneck (90% of the run time). The real fix is to use a hash table rather than an alist. Here is a patch (against the stable branch) that does this: Index: libguile/gc.c =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/gc.c,v retrieving revision 1.208.2.11 diff -u -p -r1.208.2.11 gc.c --- libguile/gc.c 1 Oct 2003 19:51:43 -0000 1.208.2.11 +++ libguile/gc.c 8 Jul 2004 19:28:45 -0000 @@ -2827,7 +2827,7 @@ scm_init_storage () #endif #endif - scm_stand_in_procs = SCM_EOL; + scm_stand_in_procs = scm_c_make_hash_table (257); scm_permobjs = SCM_EOL; scm_protects = scm_c_make_hash_table (31); scm_gc_registered_roots = scm_c_make_hash_table (31); Index: libguile/procprop.c =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/procprop.c,v retrieving revision 1.37.2.2 diff -u -p -r1.37.2.2 procprop.c --- libguile/procprop.c 14 Mar 2002 05:26:15 -0000 1.37.2.2 +++ libguile/procprop.c 8 Jul 2004 19:28:45 -0000 @@ -52,6 +52,7 @@ #include "libguile/smob.h" #include "libguile/root.h" #include "libguile/vectors.h" +#include "libguile/hashtab.h" #include "libguile/validate.h" #include "libguile/procprop.h" @@ -159,15 +160,16 @@ scm_i_procedure_arity (SCM proc) static SCM scm_stand_in_scm_proc(SCM proc) { - SCM answer; - answer = scm_assoc (proc, scm_stand_in_procs); - if (SCM_FALSEP (answer)) + SCM handle, answer; + handle = scm_hashq_get_handle (scm_stand_in_procs, proc); + if (SCM_FALSEP (handle)) { answer = scm_closure (scm_list_2 (SCM_EOL, SCM_BOOL_F), SCM_EOL); - scm_stand_in_procs = scm_acons (proc, answer, scm_stand_in_procs); + scm_hashq_set_x (scm_stand_in_procs, proc, answer); } - else - answer = SCM_CDR (answer); + else { + answer = SCM_CDR(handle); + } return answer; } With this patch, I get about the same timings as without tracing. guile> (trace load) $3 = (load-module) guile> (time (apropos "doesntexist")) ;; Evaluation took: ;; 0.05 seconds of real time ;; 0.05 seconds of user time ;; 0 seconds of system time Could someone please put the fix in CVS (stable branch and CVS HEAD)? Thanks. -- Matthias Koeppe -- http://www.math.uni-magdeburg.de/~mkoeppe _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel