defmulti "miss" performance poor

Description

I'm seeing a performance problem with clojurescripts defmulti:

  • dispatch is slow when there is no match for the dispatch value

  • slowness increases as the method-table grows ~O

Verified with optimisations :none and :advanced.

Verified not to be an issue for Clojure on JVM.

Example 1: Dispatch and hit

Example 2: Dispatch and miss

Example 3: More methods (x10)

Environment

None

Attachments

1

Activity

Show:

António Monteiro May 15, 2017 at 3:13 AM

Attached patch with fix. The patch applies the same changes that were applied to Clojure in the following commit: https://github.com/clojure/clojure/commit/6d305a0959183acb75fc44f9192eed2abf33bf25. Benchmarks of before and after in my machine are shown below.

Example | Before | After
1 | 2.642308 msecs | 3.099353 msecs
2 | 72.614162 msecs | 7.423098 msecs
3 | 212.955697 msecs | 19.691014 msecs

Oliver George May 2, 2017 at 11:53 PM

I think this affects a common use case: using defmulti as an extension point but rely on default behaviour most of the time.

Completed

Details

Assignee

Reporter

Patch

Code

Fix versions

Priority

Created May 2, 2017 at 11:52 AM
Updated May 15, 2017 at 12:44 PM
Resolved May 15, 2017 at 12:44 PM