Skip to content

palisades-lakes/multimethod-experiments

Repository files navigation

multimethod-experiments

Clojars Project

This repository is intended as something like reproducible research, to document in detail what led to 2 libraries:

  • faster-multimethods: a faster backwards-compatible alternative to the Clojure 1.8.0 implementation,

  • dynamic-functions: not backwards compatible, more restricted than Clojure multimethods, but faster still.

Clojure provides about a dozen competing variations on 'object-oriented' or 'polymorphic' functionality, including: definterface, defmulti/defmethod, multi-arity defn, defprotocol, defrecord, defstruct, deftype, gen-class, reify, and proxy. See Chas Emerick's Flowchart for choosing the right Clojure type definition form for a comparison and evaluation of when to use which. (Note that it doesn't include defmulti/defmethod.)

Of the non-deprecated ones, defmulti/defmethod seems to one of the least used (though I have no hard data for that). This may in part be due to the general advice on the web, which is to use defprotocol rather than defmulti, because defmutli is 'slow' by comparison.

The motivation for this project was, first, to create some realistic enough benchmarks (at least for the kinds of problems I work on) to measure the cost of using defmulti versus various alternatives. Second, I wanted to understand the current Clojure implementation. Third, I was curious whether significant performance improvements can be achieved with small changes to the existing implementation, provided as a library layered on top of Clojure, or would compiler level changes be required.

For general background on generic functions (aka multimethods), from my perspective, see generic_functions.

For notes on the Clojure 1.8.0 implementation, see Clojure 1.8.0 multimethods.

For descriptions of the current benchmarks, and results, see benchmarks.

Installation

Clone the repository and build from source using Maven, for example:

mvn package

License

Copyright © 2017 John Alan McDonald

Apache 2.0

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

Experiments with implementation and design variations related to Clojure's `defmulti`/`defmethod`/`MultiFn`.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published