[racket-dev] Embedded racket is much slower in thread 'heavy' programs

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Fri Dec 14 01:57:54 EST 2012

I have a program which is thread 'heavy' and runs much slower in embedded
racket (vim) than it does in pure racket.

The program: (note no #lang, as I'm doing this in the repl)

(require racket/async-channel)

(define (make-passer in)
  (define chan (make-async-channel))
  (thread (lambda ()
    (async-channel-put chan (sync in))))
  chan)

(define (run-passers num)
  (define input (make-async-channel))
  (define output
    (for/fold ((chan input)) ((i num))
      (make-passer chan)))
  (define start-time (current-inexact-milliseconds))
  (async-channel-put input #f)
  (sync output)
  (define end-time (current-inexact-milliseconds))
  (- end-time start-time))

(define times '())

(thread
 (lambda ()
   (collect-garbage)
   (set! times (cons (run-passers 3) times))
   (collect-garbage)
   (set! times (cons (run-passers 3) times))
   (collect-garbage)
   (set! times (cons (run-passers 3) times))))


If you examine the times variable after sufficient time you get the
following:
In racket: (0.14501953125 0.134765625 0.619873046875)
In vim: (10706.1171875 10999.6611328125 9998.8330078125)

If I don't do in in a separate thread, then vim is comparable because it is
using the racket scheduler, and not calling scheme_check_threads. Vim calls
scheme_check_threads every bit (I think 10 times a second), but it looks
like not much progress is made on each of these steps. I can understand if
it was slightly slower, but a factor of over 50k is a bit too much. Is it
possible for scheme_check_threads to do more work on each invocation in a
scenario like this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20121213/e1797fea/attachment-0001.html>

Posted on the dev mailing list.