It looks like you may want `define-inline' from `racket/performance-hint'.

Vincent



At Thu, 22 Aug 2013 11:11:51 -0400,
Sam Tobin-Hochstadt wrote:
> 
> Ah, indeed.  I'm calling `random` in the closure now.  Fixing that
> removes the anomaly.
> 
> Sam
> 
> On Thu, Aug 22, 2013 at 11:05 AM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> > At Thu, 22 Aug 2013 10:59:35 -0400, Sam Tobin-Hochstadt wrote:
> >> This short program generates a lot of closures, and thus doesn't run very 
> >> fast.
> >>
> >> #lang racket/base
> >>
> >> (require racket/flonum)
> >>
> >> (define (Point x0 x1 y0 y1)
> >>   (list (λ () (let ([x (- x1 x0)] [y (- y1 y0)])
> >>                 (flsqrt (+ (* x x) (* y y)))))))
> >>
> >> (define iter 1e4)
> >> (for ([i (in-range iter)])
> >>   (define p (Point (random) (random) (random) (random)))
> >>   (define f (car p))
> >>   (for ([i (in-range 1e3)])
> >>     (f)))
> >>
> >> I tried manually inlining `Point` by replacing `define` with
> >> `define-syntax-rule`, and the program gets about 8x *slower*.  I don't
> >> have any idea why this is happening, especially since `Point` is
> >> actually inlined by the optimizer in the `define` case.
> >>
> >> Any idea why this might be?
> >
> > Using `define-syntax-rule' changes the program from
> >
> >  (let ([x (random)])
> >    (call-a-lot (lambda () x)))
> >
> > to
> >
> >  (call-a-lot (lambda () (random)))
> >
> >
> > Did you mean to try
> >
> >  (define (Point x0 x1 y0 y1)
> >    (let ([x (- x1 x0)] [y (- y1 y0)])
> >      (let ([v (flsqrt (+ (* x x) (* y y)))])
> >        (list (λ () v)))))
> >
> > ?
> >
> 
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev

Reply via email to