performance tuning of srfi-57 implementations Per Bothner 20 Dec 2004 07:43 UTC

As others have pointed out: the srfi-57 implementation is dog slow.
In the case of Kawa, this may be indicating Kawa bugs I haven't
tracked down yet and profiling may find places where my
  implementation is doing something silly.

In addition, I think it should be possible to tweak the code to
make it run faster on all/mot implementations.  Unfortuantely,
I don't pretend to understand the code (at least not yet),
but here are some ideas:

* The build-record macros seems to be always used with a
fixed integer first argument. Why not split it up into
multiple macros: (build-record 0 ...) -> (build-record-0 ...)
and so on.  This is likely to be a win, since implementations
spend less time searching through the clauses.  (Not a huge win,
assuming non-matching clauses will quickly fail quickly, but still
likely to be an improvement.)

* Avoid taking apart lists.  Instead of:
(define-syntax meta
   (syntax-rules (meta quasiquote unquote)
     ((meta `(meta ,(function . arguments)) k)
      (meta `(argument ...) (syntax-apply-to function k)))
do:
(define-syntax meta
   (syntax-rules (meta quasiquote unquote)
     ((meta `(meta ,(function . arguments)) k)
      (meta `argument (syntax-apply-to function k)))
I.e. replace "argument ..." by ". arguments" which
is likely to be much faster.

* I don't understand how the meta rule works, but would
it be possible to remove the outer layer of quasiquote?
I.e.:
(define-syntax meta-qq
   (syntax-rules (meta-unquote)
     ((meta-qq (meta-unquote function . arguments) k)
      (meta-qq arguments (syntax-apply-to function k)))
     ((meta-qq (a . b) k)
      (meta-qq a (descend-right b k)))
     ((meta-qq whatever k) (syntax-apply k whatever))
     ((meta-qq arg)
      (meta-qq arg (syntax-id)))))

* Avoid comparing string literals like "is-scheme?".
(No specific suggestion here.)
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/