[racket] Everything type-checks; on to benchmarking and optimization

From: Stephen Bloch (bloch at adelphi.edu)
Date: Fri Feb 28 10:50:11 EST 2014

On Feb 28, 2014, at 10:34 AM, Vincent St-Amour <stamourv at ccs.neu.edu> wrote:

> This code is probably the problem:
> 
>    (require/typed racket/unsafe/ops
>                   [(unsafe-fx+ index+) [Index Index -> Index]]
>                   [unsafe-fx+    [Fixnum Fixnum -> Fixnum]]
>                   [unsafe-fx- (Fixnum Fixnum -> Fixnum)]
>                   [unsafe-fl+ (Flonum Flonum -> Flonum)]
>                   [unsafe-fl- (Flonum Flonum -> Flonum)]
>                   [unsafe-fl* (Flonum Flonum -> Flonum)]
>                   )
> 
> TR already provides types for these functions, so you can use:
> 
>    (require racket/unsafe/ops)
> 
> `require/typed' adds contracts to its imports (for safe typed-untyped
> interop), which add a significant cost (85% of the running time,
> according to the contract profiler).

Yike!  Thanks; I never would have thought of that.

There’s probably something in the documentation about “require/typed” as a source of inefficiency, but for whatever reason I didn’t stumble upon it.

> Removing the `require/typed' (except for `index+') brings the running
> time (of the portion you were profiling) down from 22s to 15s. Replacing
> the `index+'s with generic `+' and `assert's (to enforce `Index'
> results) brings the running time down to 2.5s.

Generic ‘+’, not ‘unsafe-fx+’?

Should I be using racket/unsafe/ops at all?


Stephen Bloch
sbloch at adelphi.edu



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.racket-lang.org/users/archive/attachments/20140228/a72065f8/attachment-0001.sig>

Posted on the users mailing list.