[racket-dev] Math library initial commit almost ready; comments on issues welcome

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Thu Oct 4 10:23:41 EDT 2012

On Mon, Oct 1, 2012 at 6:49 PM, Neil Toronto <neil.toronto at gmail.com> wrote:
> This is similar to the testing code I wrote, and it also exhibits quadratic
> behavior. The `apply*' macro generates the simplest deep expression
> possible. It's used to repeatedly apply a function with the simplest
> one-argument floating-point type possible.
> #lang typed/racket/base #:no-optimize
> (require racket/flonum
>          (for-syntax racket/base))
> (define-syntax (apply* stx)
>   (syntax-case stx ()
>     [(_ f x 0)  #'(f x)]
>     [(_ f x n)  #`(f (apply* f x #,(- (syntax->datum #'n) 1)))]))
> (: simple-flabs (Flonum -> Flonum))
> (define simple-flabs flabs)
> (: flabs* (Flonum -> Flonum))
> (define (flabs* x)
>   (apply* simple-flabs x 1000))
> Typechecking is quadratic in the number of nested applications done in
> `flabs*'. Changing `simple-flabs' to `flabs' doubles the time; changing it
> to `abs' apparently changes typechecking to O(n^3).

As far as I can tell, there's not actually quadratic behavior here,
it's just slow. However, the major slowness seems to be in
`syntax-parse` itself, or at least that's what the profiler shows.

As a simple benchmark, I tried writing a little syntax analyzing
function in syntax-parse, syntax-case, and match:
https://gist.github.com/3828408 .  Unfortunately, it shows that
`syntax-parse` is about 4x slower than `syntax-case`, and `match` is
2.5x faster again. Hopefully, there are ways to work around this, and
I won't have to avoid `syntax-parse`.
sam th
samth at ccs.neu.edu

Posted on the dev mailing list.