Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/redplanetlabs/proxy-plus
A replacement for Clojure's proxy that's 10x faster and more usable
https://github.com/redplanetlabs/proxy-plus
Last synced: 3 days ago
JSON representation
A replacement for Clojure's proxy that's 10x faster and more usable
- Host: GitHub
- URL: https://github.com/redplanetlabs/proxy-plus
- Owner: redplanetlabs
- License: apache-2.0
- Created: 2019-12-20T19:54:41.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-13T04:34:21.000Z (9 months ago)
- Last Synced: 2025-01-29T16:04:30.527Z (10 days ago)
- Language: Clojure
- Homepage:
- Size: 34.2 KB
- Stars: 175
- Watchers: 9
- Forks: 11
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# proxy-plus
`proxy+` is a replacement for Clojure's `proxy` that's faster and more usable. `proxy` has a strange implementation where it overrides every possible method and uses a mutable field to store a map of string -> function for dispatching the methods. This causes it to be unable to handle methods with the same name but different arities.
`proxy+` fixes these issues with `proxy`. Usage is like `reify`, and it's up to 10x faster.
## Latest version
The latest release version of proxy-plus is hosted on [Clojars](https://clojars.org):
[![Current Version](https://clojars.org/com.rpl/proxy-plus/latest-version.svg)](https://clojars.org/com.rpl/proxy-plus)
Note that proxy-plus has a dependency on `rama-shaded-asm`, which is hosted on a private Maven repo at `https://nexus.redplanetlabs.com/repository/maven-public-releases`. You'll need to include this repository in your build to resolve the dependencies of proxy-plus.
## Usage
This library provides the macro `proxy+`. The first argument is fields to provide to the superclass's constructor. Next comes `reify`-like definitions to provide overrides. When extending a base class, the base class should come first. Example usage:
```clj
(proxy+ [super-arg1 super-arg2]
BaseClass
(foo [this] -1)
(foo [this a b] (+ a b))SomeInterface
(bar [this a b c] (* a b c))SomeInterface2
(bar [this] 100)
)
```## Benchmark
The code for this benchmark is in `scripts/benchmarks.clj`.
```
proxy one override dispatch performance (10,000 iterations):
------------------------------------------------------------
Evaluation count : 405960 in 60 samples of 6766 calls.
Execution time mean : 151.149913 µs
Execution time std-deviation : 3.993821 µs
Execution time lower quantile : 147.409234 µs ( 2.5%)
Execution time upper quantile : 162.450275 µs (97.5%)
Overhead used : 1.683863 nsFound 6 outliers in 60 samples (10.0000 %)
low-severe 3 (5.0000 %)
low-mild 3 (5.0000 %)
Variance from outliers : 14.1608 % Variance is moderately inflated by outliersproxy+ one override dispatch performance (10,000 iterations):
-------------------------------------------------------------
Evaluation count : 1126260 in 60 samples of 18771 calls.
Execution time mean : 54.002204 µs
Execution time std-deviation : 561.796450 ns
Execution time lower quantile : 53.246506 µs ( 2.5%)
Execution time upper quantile : 55.310651 µs (97.5%)
Overhead used : 1.683863 nsFound 3 outliers in 60 samples (5.0000 %)
low-severe 3 (5.0000 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliersproxy ten overrides dispatch performance (10,000 iterations):
-------------------------------------------------------------
Evaluation count : 15780 in 60 samples of 263 calls.
Execution time mean : 3.835142 ms
Execution time std-deviation : 53.304494 µs
Execution time lower quantile : 3.727639 ms ( 2.5%)
Execution time upper quantile : 3.959029 ms (97.5%)
Overhead used : 1.721424 nsFound 4 outliers in 60 samples (6.6667 %)
low-severe 1 (1.6667 %)
low-mild 3 (5.0000 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliersproxy+ ten overrides dispatch performance (10,000 iterations):
--------------------------------------------------------------
Evaluation count : 146280 in 60 samples of 2438 calls.
Execution time mean : 416.130110 µs
Execution time std-deviation : 7.529965 µs
Execution time lower quantile : 406.496697 µs ( 2.5%)
Execution time upper quantile : 431.908321 µs (97.5%)
Overhead used : 1.721424 nsFound 7 outliers in 60 samples (11.6667 %)
low-severe 7 (11.6667 %)
Variance from outliers : 7.7810 % Variance is slightly inflated by outliers
```## License
Copyright 2020 Red Planet Labs, Inc. proxy-plus is licensed under Apache License v2.0.