[racket-dev] for loop singleton optimization

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Nov 28 12:58:09 EST 2012

I think that would be an ad hoc optimization in each `in-'. For example,

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
    (syntax-case stx ()
      [[(id) (_ st)]
       ....

in `racket/set' could change to

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
    (syntax-case stx (set)
      [[(id) (_ (set v))]
       #`[(id) (in-value v)]]
      [[(id) (_ st)]
       ....


At Wed, 28 Nov 2012 12:50:49 -0500 (EST), "J. Ian Johnson" wrote:
> It would be great to optimize singletons out of comprehensions, since I (and 
> probably others) have macros that expand into singleton constructors that are 
> much better suited to just be a rebinding.
> 
> > (time (for ([n (in-range 1 1000000)]) (for ([k (in-set (set n))]) (random 
> k))))
> cpu time: 340 real time: 338 gc time: 16
> > (time (for ([n (in-range 1 1000000)]) (for ([k (in-value n)]) (random k))))
> cpu time: 120 real time: 118 gc time: 0
> 
> Is this easily added to for.rkt?
> 
> -Ian
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev

Posted on the dev mailing list.