Optimized version of the '<' and '>' functions for arties larger than 2

Description

When looking at the code of the build-in functions '<' and '>', (next more) is invoked twice in each comparison of two neighboring arguments.

Proposed: Compute (next more) only once per 'iteration' for the following set of functions that have the same code pattern: =, ==, <, <=, >, >=.

Perf improvements (see comments for more details):

Function

Arity

Before

After

% improved

<

4

140.7 ns

141.6 ns

-0.6%

<

10

505.3 ns

460.3 ns

8.9%

<

100

9.0 µs

8.6 µs

4.4%

<

10000

885 µs

851 µs

3.8%

=

4

86.1 ns

86.8 ns

0.8%

=

10

333.4 ns

300.6 ns

9.8%

=

100

4.28 µs

3.65 µs

14.7%

=

10000

397.4 µs

353.3 µs

11.0%

==

4

138.1 ns

135.7 ns

1.7%

==

10

487.9 ns

460.9 ns

5.5%

==

100

5.58 µs

5.27 µs

5.6%

==

10000

565.0 µs

537.7 µs

4.8%


Patch: clj-1912.patch

Environment

None

Attachments

2

Activity

Show:

Alex Miller May 15, 2017 at 10:09 PM

see

Nikita Prokopov May 15, 2017 at 9:45 PM

The patch from gives you much more substantial advantage by introducing real 3-arities instead of just optimizing away one of two next calls. 70-80% improvement vs 5-10% here.

Jozef Wagner December 2, 2016 at 9:25 AM

Benchmarks for <

Benchmarks for =

Benchmarks for ==

Benchmark code

Alex Miller December 2, 2016 at 2:22 AM

Can you include benchmark code and benchmarks?

Jozef Wagner December 1, 2016 at 8:19 PM

Patch added. As if-let is defined later in the file, a combination of let and if is used.

Duplicate

Details

Assignee

Reporter

Approval

Triaged

Patch

Code

Priority

Affects versions

Created April 8, 2016 at 10:11 PM
Updated May 15, 2017 at 10:09 PM
Resolved May 15, 2017 at 10:09 PM