[plt-scheme] weird macro expansion performance

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Nov 22 20:28:29 EST 2003

At Sat, 22 Nov 2003 18:26:02 -0500, Pedro Pinto wrote:
> Expanding:
>     (test-macro 15000)
> Takes an inordinate amount of time on MzScheme (36 seconds on my  1.8 
> Athlon)  with time growing linearly with n. 

Technically, expansion was actually fast. It goes wrong in

DrScheme (and errortrace) map eval over the content of a top-level
`begin'. Internally, MzScheme does the same thing, but it was failing
to re-initialize some state for each iteration. (More accurately, a
container was passed into the function with the loop, when it should
have been generated inside the loop.) This is fixed and exp-tagged in

I thought I had a workaround, but there was another problem. Using a
single `define-values' is about five times as fast...

(define-macro (test-macro n)
  (define (gen-symbols n)
    (if (= n 0)
        (cons (string->symbol (string-append "sym" (number->string n)))
              (gen-symbols (- n 1)))))
  (let ([syms (gen-symbols n)])
    `(define-values ,syms (values ,@(map (lambda (s) 1) syms)))))

... but that's still too slow. For some reason, `define-values' wasn't
using the hash-table-based dup checker. I've fixed that, too.

The only workarounds I see for v205 are to put the code into a module
or change the eval handler.


Posted on the users mailing list.