[plt-scheme] Science Collection
At Mon, 4 Oct 2004 06:46:29 -0700, "Williams, M. Douglas" wrote:
> 3. In the last week, I updated all of the modules to use provide/contract
> to define and enforce parameter (and result) types, ranges, and
> inter-argument constraints. I really like the concept and think it's a
> great feature. However, it seems (very subjective here) that my examples
> run about an order of magnitude slower than before. [To be fair, nothing is
> pre-compiled and much of that may be overhead due to compilation time when
> they are loaded.] Does anyone have a good handle on the overhead associated
> with using contracts?
There is a known performance bug with contracts. If you refer to a
variable with a contract inside a loop, the performance is much worse
than if you refer to it outside a loop.
For example, with this in one module:
(define (f x) x)
(provide/contract [f (integer? . -> . integer?)])
Then this is very very slow:
(define (count n)
(unless (zero? n)
(f n)
(count (- n 1))))
Whereas this:
(define local-f f)
(define (count n)
(unless (zero? n)
(local-f n)
(count (- n 1))))
is not (still slower, but not absurdly so). We're working on a solution
to this, but haven't gotten one yet.
If you're seeing something else, perhaps a small example would help me
figure out what's going on.
Robby