[racket] Is eval very slow?

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jul 19 03:46:16 EDT 2012

Just now, John Clements wrote:
> I don't think you should be shocked; I believe that calls to eval
> are essentially triggering full passes of the parser and compiler,
> dynamically. It's true that you could optimize for certain special
> cases (such as yours), but generally speaking these use cases are
> rare, particularly since I'm guessing that the places where this
> optimization would be possible are also the places where eval isn't
> needed.

As a sidenote, this is not something that is unique to racket or that
is new in any way...  I first "encountered" this in 1995 in a project
written in Allegro Lisp -- I was surprised about how slow `eval' was,
and when I asked about it, the advice I was given is that in extreme
cases where you really need a fast evaluation of dynamically generated
code, you're better off writing a mini-evaluator instead.

(Another sidenote: there are some languages with a "very fast" eval,
like elisp and newlisp.  In these languages it can be as fast as
running normal code, but this is because there is little to no
compilation done.)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.