https://github.com/palisades-lakes/multimethod-experiments
Experiments with implementation and design variations related to Clojure's `defmulti`/`defmethod`/`MultiFn`.
https://github.com/palisades-lakes/multimethod-experiments
benchmark clojure-multimethods generic-functions multimethods
Last synced: 17 days ago
JSON representation
Experiments with implementation and design variations related to Clojure's `defmulti`/`defmethod`/`MultiFn`.
- Host: GitHub
- URL: https://github.com/palisades-lakes/multimethod-experiments
- Owner: palisades-lakes
- License: apache-2.0
- Created: 2017-08-08T21:14:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-01T19:08:46.000Z (over 1 year ago)
- Last Synced: 2025-03-25T09:49:25.571Z (about 1 month ago)
- Topics: benchmark, clojure-multimethods, generic-functions, multimethods
- Language: Clojure
- Size: 9.37 MB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# multimethod-experiments
[](https://clojars.org/palisades-lakes/multimethod-experiments)
This repository is intended as something like reproducible research,
to document in detail what led to 2 libraries:- [faster-multimethods](https://github.com/palisades-lakes/faster-multimethods):
a faster backwards-compatible alternative to the Clojure 1.8.0
implementation,- [dynamic-functions](https://github.com/palisades-lakes/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](https://cemerick.com/2011/07/05/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](docs/generic_functions.md).For notes on the Clojure 1.8.0 implementation,
see [Clojure 1.8.0 multimethods](docs/implementation_notes_1.8.0.md).For descriptions of the current benchmarks, and results,
see [benchmarks](docs/benchmarks.md).## Installation
Clone the repository and build from source using Maven,
for example:
```
mvn package
```## License
Copyright © 2017 John Alan McDonald
[Apache 2.0](LICENSE)
## Acknowledgments
### 
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: