[plt-dev] performance-oriented unsafe operations (v4.2.1.8)

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Sep 6 14:27:27 EDT 2009

Version (now in SVN) starts an experiment with
performance-oriented unsafe operations.

The new `scheme/unsafe/ops' library provides operations such as
`unsafe-vector-ref' and `unsafe-fl+' (for inexact real addition) that
are inlined by the JIT without contract checks. If a call violates the
contract of a function from `scheme/unsafe/ops', arbitrarily bad
things can happen. As long as contracts are satisfied, however,
performance should be a little better than with corresponding safe

As part of the experiment, the expansion of `for' with `in-range' and
`in-vector' now uses unsafe operations (in a safe way). For example,
`in-vector' uses `unsafe-vector-ref' as well as a fixnum comparison
for detecting when it has reached the end of a vector; it also uses
unsafe fixnum arithmetic to increment the index as long as the step is
1 or -1 (in which case no overflow can occur during the
increment). These improvements make a 10-20% difference in a tight
loop over a vector.

Future possible directions include making the JIT specialize
combinations of inexact operations to avoid boxing intermediate

The exports of `scheme/unsafe/ops' are protected, so that a code
inspector can prevent access to unsafe operations by untrusted code.

Posted on the dev mailing list.