
In particular, instead of going directly back to the chaperone, handle the case where the function doesn't accept keyword arguments with a less expensive fallback. The less expensive fallback uses a case-lambda wrapper (wrapped inside a make-keyword-procedure) to close over the neg-party and avoid the chaperone creation. With this commit, the program below gets about 3x faster, and is only about 20% slower than the version that replaces the "(let ([f f]) ...)" with its body #lang racket/base (module m racket/base (require racket/contract/base) (provide (contract-out [f (-> integer? integer?)])) (define (f x) x)) (require 'm) (collect-garbage) (time (for ([x (in-range 5000000)]) (let ([f f]) (f 1)))) Thanks, @samth!
28 lines
773 B
Racket
28 lines
773 B
Racket
#lang racket/base
|
|
(require scribble/manual)
|
|
|
|
(provide add-use-sources declare-exporting-ctc)
|
|
|
|
(define-syntax-rule
|
|
(add-use-sources (x y ...))
|
|
(x y ...
|
|
#:use-sources
|
|
(racket/contract/private/base
|
|
racket/contract/private/misc
|
|
racket/contract/private/provide
|
|
racket/contract/private/guts
|
|
racket/contract/private/prop
|
|
racket/contract/private/blame
|
|
racket/contract/private/ds
|
|
racket/contract/private/opt
|
|
racket/contract/private/basic-opters
|
|
|
|
racket/contract/private/box
|
|
racket/contract/private/hash
|
|
racket/contract/private/vector
|
|
racket/contract/private/struct-dc)))
|
|
|
|
(define-syntax-rule
|
|
(declare-exporting-ctc mod)
|
|
(add-use-sources (declare-exporting mod racket/contract racket)))
|