[CM] Performance of S7

Massimiliano Gubinelli m.gubinelli at gmail.com
Fri Jan 1 15:06:12 PST 2021


Thanks,
 I've tried to use

> (define define-macro define-expansion)

in my code and indeed seems to lead to a small improvement.  However things are still quite slow. This really puzzles me since in all the small benchmarks I've tried s7 is much faster than Guile 1.8.

For the moment I noticed that the following code (which is a pattern we use a lot)

(define fib (lambda args #f))
(set! fib (lambda (n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2))))))

(let ((n 40))
    (display (format #f "(fib ~A) : ~A \n" n (fib n))))

leads to a ~10x slowdown compared to a direct definition. So now I tend to think that this could be one of the major causes of what I see.

Anyway I still need to study a bit more the s7 sources and all the differences between macros and expansions to have a clearer picture of what is going on with my code.

Best,
Massimiliano



> On 31. Dec 2020, at 22:15, bil at ccrma.stanford.edu <bil at ccrma.Stanford.EDU> wrote:
> 
> I haven't had a chance to look at the code yet, but
> I think Kjetil is saying you are using define-macro
> throughout your code.  In s7 macros are "first class"
> entities, so a macro can be local, or passed as
> a function argument, etc.  That means there's no
> way to expand the macro at load time and splice
> it into the code.  define-expansion is like define-macro,
> but it does expand (at read time), somewhat like
> other schemes/lisps handle this, at least in the sense
> that the expansion-macro is only expanded once per
> occurrence in the code. You might try
> 
> (define define-macro define-expansion)
> 
> to automatically turn all s7-macros into normal-macros,
> but any name collisions will cause confusion (the
> reader only sees the current global environment,
> and know nothing about the local code structure).
> 
> 




More information about the Cmdist mailing list