Skip to content

Almost backwards compatible alternative to Clojure 1.8.0 implementation of multimethods with roughly 1/10 the method lookup cost.

License

Notifications You must be signed in to change notification settings

palisades-lakes/faster-multimethods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

faster-multimethods

Clojars Project

Alternative to the Clojure 1.8.0 implementation of generic functions (aka multimethods) via defmulti/defmethod/MultiFn.

Very roughly 1/10 the cost for method lookup of Clojure 1.8.0, and comparable in performance to using protocols, while being fully dynamic.

Brief benchmark discussion is in benchmarks

A change history, including differences from Clojure 1.8.0, is in changes.

Dependency

Maven:

<dependency>
  <groupId>palisades-lakes</groupId>
  <artifactId>faster-multimethods</artifactId>
  <version>0.1.0</version>
</dependency>

Leiningen/Boot:

[palisades-lakes/faster-multimethods "0.1.0"]

Code examples

Fastest:

(require `[palisades.lakes.multimethods.core :as plm])

(plm/defmulti intersects?
  "Test for general set intersection."
  {}  
  plm/signature
  :hierarchy false)
  
(plm/defmethod intersects? 
  (plm/to-signature IntegerInterval java.util.Set)
  [^IntegerInterval s0 ^java.util.Set s1]
  (.intersects s0 s1))
...

Most general:

(require `[palisades.lakes.multimethods.core :as plm])

(plm/defmulti intersects?
  "Test for general set intersection."
  {}  
  (fn intersects?-dispatch [s0 s1] [(class s0) (class s1))))
(plm/defmethod intersects? 
  [IntegerInterval java.util.Set]
  [^IntegerInterval s0 ^java.util.Set s1]
  (some #(.contains s0 %) s1))
...

Acknowledgments

Yourkit

YourKit is kindly supporting open source projects with its full-featured Java Profiler.

YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications. Take a look at YourKit's leading software products:

About

Almost backwards compatible alternative to Clojure 1.8.0 implementation of multimethods with roughly 1/10 the method lookup cost.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages