On 5/2/25 8:56 AM, David Scherfgen wrote:
eq is a single machine instruction in most Lisp implementations and is
inlined, i.e. doesn't require a function call.
In contrast, eql is usually not inlined - it incurs the overhead of a
function call and performs additional type checks if eq returns nil.
Some experiments with SBCL show a factor ~10 difference in performance
between eq and eql.
Does it matter within Maxima? Maybe. member is called extremely often,
and during a test suite run, it's the top #7 function where time is
being spent.
Maxima basically uses member as a short way of writing:
(or (eq ...) (eq ...) ...)
I'd argue that in this long-form, if we know we're working with
symbols, we would definitely use eq, not eql. So if we optimize for eq
in long-form code, shouldn't we be just as deliberate when using member?
I'm not sure we are (were) actually really deliberate about using `eq`
instead `eql`. Some of the code is really, really old.
But I have no issues with replacing appropriate calls to `member` with
`memq` instead. That makes it clearer we really do want `eq` and, if
needed, we can supply a compiler macro to further optimize the calls, as
needed.