Variadic vector-of overload has poor performance

Description

Times after a few runs ~335 ms.

Times after a few runs ~5 ms.

Cause: The variadic case for vector-of is missing a type hint and uses reflection - this will be seen in any call to vector-of with more than 4 elements.

Approach: Switch interop call to instead use conj - there is no reason to be using interop here over standard conj on a vector. The after time for the first case above is 6-9 ms depending on GC (the fast reduce path in repeat reduces gc variability I think).

Patch: clj-1695-2.patch

Environment

None

Attachments

2

Activity

Show:

Alex Miller April 10, 2015 at 3:52 PM

Switched interop call to just

Alex Miller April 6, 2015 at 5:37 PM

Attached new patch with more generic typehint, placed more specifically where it's needed.

Michael Blume April 6, 2015 at 5:15 PM

Actually I'm wrong, type-hinting the return of vector-of (as either Vec or IPersistentCollection) doesn't remove the reflection.

Alex Miller April 6, 2015 at 5:10 PM

I went back-and-forth on that but it didn't seem like that any other code could benefit from the return type hint?

Re-thinking, maybe the hint should actually be more generic and hint to clojure.lang.IPersistentCollection instead.

Michael Blume April 6, 2015 at 5:02 PM

If we're adding a type-hint anyway, wouldn't it be more effective to type-hint the return value of vector-of?

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code

Priority

Affects versions

Fix versions

Created April 3, 2015 at 8:53 PM
Updated April 10, 2015 at 4:58 PM
Resolved April 10, 2015 at 4:58 PM