Unroll constantly to improve performance of multi-arity calls

Description

This was found to be a hot spot when testing some Specter use cases.

Review of common uses of constantly shows that the arity 1 case is the most common use of `constantly` in the wild, so only unrolled to two arguments.

Perf test:

Patch: 0001-CLJ-2228-Improve-performance-of-constantly.patch

Prescreened by: Alex Miller

Environment

None

Attachments

1

Activity

Show:

import September 27, 2017 at 9:37 PM

Comment made by: nathanmarz

Specter uses constantly for arity 1, so this patch is sufficient for Specter.

Alex Miller August 29, 2017 at 2:04 PM

I did some poking around and I suspect arity 1 is the 98% use case and arity 0 making up most of the rest. I failed to actually find an example of any arity >1 although I'm sure there are a few of them out there. I think unrolling to arity 2 would be more than sufficient.

Alex Miller August 29, 2017 at 1:38 PM

What is the max arity for constantly you encounter in Specter?

Alex Miller August 29, 2017 at 1:30 PM

I want to call out to our workflow diagram at https://dev.clojure.org/display/community/JIRA+workflow for process here. I've triaged this, but it's unlikely to be reviewed for the next release at this point unless it's been prescreened, and that requires a patch. So it would be helpful if you could:

  • mention your use case where this made a difference (Specter)

  • attach a patch

  • include the benchmarks in the ticket description

One question I have is how many arities to unroll. 10 seems like a lot? My guess is that up to 2 or 3 args would cover 90+% of cases but could poke around in https://crossclj.info/fun/clojure.core/constantly.html or do some other research to get an idea.

Details

Assignee

Reporter

Approval

Prescreened

Patch

Code and Test

Priority

Created August 28, 2017 at 9:22 PM
Updated October 5, 2021 at 5:16 PM