guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add tree-il optimizations for equal? on char and number literals


From: Linus Björnstam
Subject: [PATCH] Add tree-il optimizations for equal? on char and number literals
Date: Wed, 13 May 2020 13:20:35 +0200
User-agent: Cyrus-JMAP/3.3.0-dev0-413-g750b809-fmstable-20200507v1

Hi there!

Aleix and I noticed that equal? has a lot higher overhead than eqv? on chars, 
which means using (ice-9 match) for chars was suboptimal. This patch fixes that.

With this patch, guile now turns (equal? #\b var) into (eqv? #\b var) and 
(equal? any-non-fixnum-number-literal var) into (eqv? 
any-non-fixnum-number-literal var). This fixes the (ice-9 match) problem, and 
means you can dispatch to equal? in macros and guile will just do the right 
thing is there are any literals.

There is one regression: it is not o(n). Currently the primitve expander is run 
once per call, which means a (equal? #\a b c d e) becomes (and (eqv? #\a b) 
(eqv? b c d e)) and that second call gets run through the primitive expander 
once again, which checks all the arguments again. The solution I see is to 
manually build the conditional code, or to just extend the old code, where only 
the comparisons directly involving the literal is optimized: (equal? a b #\c) 
-> (and (equal? a b) (eqv? b #\c)).

Any feedback is welcome.

-- 
  Linus Björnstam

Attachment: 0001-Make-equal-to-eqv-or-eq-if-any-suitable-literals-are.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]