1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Speed up the self-tail-recursive case (1x->2x)

* benchmark/lib.scm: Add a comment, update the loop disassembly. Loop is
  now faster in the VM, thankfully.

* src/vm_engine.h (CACHE_PROGRAM): Only release and regrab the object
  array handle if the program changed. That is to say, optimize the
  self-tail-recursive case. But perhaps the thing to optimize here are
  the procedure calls themselves. Worth looking at in the future.
This commit is contained in:
Andy Wingo 2008-05-25 13:34:50 +02:00
parent 22bcbe8cc9
commit e677365cbc
2 changed files with 57 additions and 68 deletions

View file

@ -3,6 +3,9 @@
;; A library of dumb functions that may be used to benchmark Guile-VM. ;; A library of dumb functions that may be used to benchmark Guile-VM.
;; The comments are from Ludovic, a while ago. The speedups now are much
;; more significant (all over 2x, sometimes 8x).
(define (fibo x) (define (fibo x)
(if (or (= x 1) (= x 2)) (if (or (= x 1) (= x 2))
1 1
@ -25,72 +28,56 @@
;; Disassembly of `loop' ;; Disassembly of `loop'
;; ;;
; Disassembly of #<objcode 302360b0>: ;; Disassembly of #<objcode b7c017e8>:
; nlocs = 0 nexts = 0 ;; nlocs = 0 nexts = 0
; 0 (make-int8 64) ;; 64 ;; 0 (make-int8 64) ;; 64
; 2 (link "=") ;; 2 (load-symbol "guile-user") ;; guile-user
; 5 (link "loop") ;; 14 (list 0 1) ;; 1 element
; 11 (link "1-") ;; 17 (load-symbol "loop") ;; loop
; 15 (vector 3) ;; 23 (link-later)
; 17 (make-int8:0) ;; 0 ;; 24 (load-symbol "guile-user") ;; guile-user
; 18 (load-symbol "n") ;; n ;; 36 (list 0 1) ;; 1 element
; 28 (make-false) ;; #f ;; 39 (load-symbol "1-") ;; 1-
; 29 (make-int8:0) ;; 0 ;; 43 (link-later)
; 30 (list 3) ;; 44 (vector 0 2) ;; 2 elements
; 32 (list 2) ;; 47 (make-int8 0) ;; 0
; 34 (list 1) ;; 49 (load-symbol "n") ;; n
; 36 (make-int8 8) ;; 8 ;; 52 (make-false) ;; #f
; 38 (make-int8 2) ;; 2 ;; 53 (make-int8 0) ;; 0
; 40 (make-int8 6) ;; 6 ;; 55 (list 0 3) ;; 3 elements
; 42 (cons) ;; 58 (list 0 2) ;; 2 elements
; 43 (cons) ;; 61 (list 0 1) ;; 1 element
; 44 (make-int8 23) ;; 23 ;; 64 (make-int8 5) ;; 5
; 46 (make-int8 4) ;; 4 ;; 66 (make-false) ;; #f
; 48 (make-int8 12) ;; 12 ;; 67 (cons)
; 50 (cons) ;; 68 (make-int8 19) ;; 19
; 51 (cons) ;; 70 (make-false) ;; #f
; 52 (make-int8 25) ;; 25 ;; 71 (cons)
; 54 (make-int8 4) ;; 4 ;; 72 (make-int8 21) ;; 21
; 56 (make-int8 6) ;; 6 ;; 74 (make-false) ;; #f
; 42 (cons) ;; 75 (cons)
; 43 (cons) ;; 76 (list 0 4) ;; 4 elements
; 44 (make-int8 23) ;; 23 ;; 79 (load-program ##{70}#)
; 46 (make-int8 4) ;; 4 ;; 102 (define "loop")
; 48 (make-int8 12) ;; 12 ;; 108 (variable-set)
; 50 (cons) ;; 109 (void)
; 51 (cons) ;; 110 (return)
; 52 (make-int8 25) ;; 25
; 54 (make-int8 4) ;; 4
; 56 (make-int8 6) ;; 6
; 58 (cons)
; 59 (cons)
; 60 (list 4)
; 62 load-program ##{201}#
; 89 (link "loop")
; 95 (variable-set)
; 96 (void)
; 97 (return)
; Bytecode ##{201}#: ;; Bytecode ##{70}#:
; 0 (object-ref 0)
; 2 (variable-ref)
; 3 (make-int8:0) ;; 0
; 4 (local-ref 0)
; 6 (call 2)
; 8 (br-if-not 0 2) ;; -> 13
; 11 (make-int8:0) ;; 0
; 12 (return)
; 13 (object-ref 1)
; 15 (variable-ref)
; 16 (object-ref 2)
; 18 (variable-ref)
; 19 (local-ref 0)
; 21 (call 1)
; 23 (tail-call 1)
;; 0 (make-int8 0) ;; 0
;; 2 (local-ref 0)
;; 4 (ee?)
;; 5 (br-if-not 0 3) ;; -> 11
;; 8 (make-int8 0) ;; 0
;; 10 (return)
;; 11 (late-variable-ref 0)
;; 13 (late-variable-ref 1)
;; 15 (local-ref 0)
;; 17 (call 1)
;; 19 (tail-call 1)
(define (loopi n) (define (loopi n)
;; Same as `loop'. ;; Same as `loop'.

View file

@ -140,6 +140,7 @@
{ \ { \
ssize_t _vincr; \ ssize_t _vincr; \
\ \
if (bp != SCM_PROGRAM_DATA (program)) { \
bp = SCM_PROGRAM_DATA (program); \ bp = SCM_PROGRAM_DATA (program); \
/* Was: objects = SCM_VELTS (bp->objs); */ \ /* Was: objects = SCM_VELTS (bp->objs); */ \
\ \
@ -148,6 +149,7 @@
\ \
objects = scm_vector_writable_elements (bp->objs, &objects_handle, \ objects = scm_vector_writable_elements (bp->objs, &objects_handle, \
&object_count, &_vincr); \ &object_count, &_vincr); \
} \
} }
#define SYNC_BEFORE_GC() \ #define SYNC_BEFORE_GC() \