[racket] Calling TR modules from Racket modules is slow?

From: John Clements (clements at brinckerhoff.org)
Date: Fri Jan 6 16:15:54 EST 2012

I'm guessing this is a contract issue, but it looks to me like calls from racket into typed/racket are slow. To wit:

#lang racket/load

(module a typed/racket 
(provide float-add)

(: float-add (Float Float -> Float))
(define (float-add a b) (+ a b))

(printf "a million in-module typed adds\n")
(define l
  (time
   (for: 
     ([i : Fixnum (in-range 1000000)])
     (float-add 0.009872 0.298719)))))

(module ut racket
  (provide untyped-float-add)
  
  (define (untyped-float-add a b) (+ a b)))

(module b racket
  (require 'a)
  (require 'ut)
  
  (provide l1 l2)
  
  (printf "a million untyped adds\n")
  (define l1
    (time
     (for ([i (in-range 1000000)])
       (untyped-float-add 0.009872 0.298719))))
  
  (printf "a million untyped->typed adds\n")
  (define l2
    (time
     (for ([i (in-range 1000000)])
       (float-add 0.009872 0.298719)))))

(require 'b)

=>

Welcome to DrRacket, version 5.2.0.7--2012-01-05(fd5e40f/g) [3m].
Language: racket/load; memory limit: 256 MB.
a million in-module typed adds
cpu time: 404 real time: 425 gc time: 273
a million untyped adds
cpu time: 372 real time: 394 gc time: 212
a million untyped->typed adds
cpu time: 3763 real time: 3979 gc time: 2077


... so in fact, TR is about the same speed as plain-old racket in adding these (even though the plain-old-racket call is across modules); I conjecture that racket's optimizer is discovering the same optimizations as TR, here.  However, making a cross-module call to a TR module is *much* slower.  Is this because this module-crossing requires a contract check?

John





-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20120106/ac08af94/attachment.p7s>

Posted on the users mailing list.