[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch for speeding up the debugging evaluator by a factor of 600
From: |
Matthias Koeppe |
Subject: |
Patch for speeding up the debugging evaluator by a factor of 600 |
Date: |
Thu, 08 Jul 2004 21:37:19 +0200 |
User-agent: |
Gnus/5.110001 (No Gnus v0.1) Emacs/21.3.50 (usg-unix-v) |
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 <address@hidden>
* 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Patch for speeding up the debugging evaluator by a factor of 600,
Matthias Koeppe <=