[r6rs-discuss] [Formal] Add symbol=? and boolean=?

From: William D Clinger <will>
Date: Fri Feb 9 22:52:54 2007

I am posting this as an individual member of the Scheme
community. I am not speaking for the R6RS editors, and
this message should not be confused with the editors'
eventual formal response.

Lauri Alanko wrote:
> Currently, symbol comparisons are often done with eq?, which seems like
> bad style, since eq? is a low-level optimization primitive with
> implementation-dependent semantics. Providing an alternative would
> hopefully encourage writing better-defined code.

The behavior of eq? on booleans and symbols is the same
in all implementations. If boolean=? and symbol=? were
slower than eq?, then many programmers would continue to
use eq? as an optimization, just as many now use eq?
instead of eqv? when comparing booleans or symbols.

If the 5.92 mustard were applied to the proposed
specification, then it appears that implementations
must raise an exception when either argument to
boolean=? (symbol=?) is not a boolean (symbol).
That means boolean=? and symbol=? are likely to be
slower than eq?, especially in systems whose compilers
do not perform common subexpression elimination and
representation inference.

John Cowan wrote:
> eqv?, however, is entirely appropriate for the job, and probably is
> as efficient, since it would be very surprising if an implementation
> of eqv? did not immediately call eq?.

Although eqv? typically calls eq? first, it must still
examine the types of its arguments when eq? returns #f.
That makes eqv? quite a bit slower than eq?.

To give some quantitative idea of the performance
issues being discussed, I wrote a small synthetic
benchmark that compares six symbols to see whether
they are distinct, using eq?, eqv?, or symbol=? [1].
For Larceny 0.93, a 2.8 GHz Pentium 4, default ten
million calls (150 million comparisons in all), the
average of five runs was:

                            seconds relative
    eq? .47 1.0
    eqv? 11.85 25.1
    symbol=? with CSE/RI 1.38 2.9
    symbol=? without CSE/RI 1.55 3.3

Before running this benchmark on the SPARC, I made
symbol=? into a primitive that gets the benefit of
all optimizations that would apply were it required
by the R6RS. On a 1.5 GHz SunBlade 1500:

                            seconds relative
    eq? 2.2 1.0
    eqv? 17.8 8.0
    symbol=? with CSE/RI 3.4 1.5
    symbol=? without CSE/RI 6.9 3.1

Common subexpression elimination (CSE) and representation
inference (RI) have little effect on the timings for eq?
and eqv?. In slower systems, the differences between eq?,
eqv?, and symbol=? will probably not appear so large, as
they will be masked by other factors.

Will

[1] http://www.ccs.neu.edu/home/will/R6RS/symtesting.sch
Received on Fri Feb 09 2007 - 22:52:47 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC