I have a program which is thread &#39;heavy&#39; and runs much slower in embedded racket (vim) than it does in pure racket.<div><br></div><div>The program: (note no #lang, as I&#39;m doing this in the repl)</div><div><br></div>
<div><div>(require racket/async-channel)</div><div><br></div><div>(define (make-passer in)</div><div>  (define chan (make-async-channel))</div><div>  (thread (lambda ()</div><div>    (async-channel-put chan (sync in))))</div>
<div>  chan)</div><div><br></div><div>(define (run-passers num)</div><div>  (define input (make-async-channel))</div><div>  (define output</div><div>    (for/fold ((chan input)) ((i num))</div><div>      (make-passer chan)))</div>
<div>  (define start-time (current-inexact-milliseconds))</div><div>  (async-channel-put input #f)</div><div>  (sync output)</div><div>  (define end-time (current-inexact-milliseconds))</div><div>  (- end-time start-time))</div>
<div><br></div><div>(define times &#39;())</div><div><br></div><div>(thread  </div><div> (lambda ()</div><div>   (collect-garbage)</div><div>   (set! times (cons (run-passers 3) times))</div><div>   (collect-garbage)</div>
<div>   (set! times (cons (run-passers 3) times))</div><div>   (collect-garbage)</div><div>   (set! times (cons (run-passers 3) times))))</div><div><br></div></div><div><br></div><div>If you examine the times variable after sufficient time you get the following:</div>
<div>In racket: (0.14501953125 0.134765625 0.619873046875)</div><div>In vim: (10706.1171875 10999.6611328125 9998.8330078125)</div><div><br></div><div>If I don&#39;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?</div>