Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster promesa.exec/wrap-bindings #156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alexandergunnarson
Copy link
Contributor

@alexandergunnarson alexandergunnarson commented Nov 18, 2024

83x faster than current implementation, per benchmarks:

(run-benchmark ; run on a single pinned core for clean test purposes
  (fn []
    (testing "`promesa.exec.csp` implementation"
      ;; 4.956172 µs — this is due to `promesa.exec/wrap-bindings`'s way of forwarding
      ;; bindings, which is 83x slower than `clojure.core/binding-conveyor-fn`
      (criterium/bench
        (csp/go))
    (testing "Bare implementation"
      ;; 59.033042 ns
      (criterium/bench
        (-> (Thread/ofVirtual)
            (.unstarted (fn []))
            (.start))))
    (testing "With `clojure.core/binding-conveyor-fn` bindings forwarding"
      ;; 58.851215 ns
      (criterium/bench
        (-> (Thread/ofVirtual)
            (.unstarted (binding-conveyor-fn (^{:once true} fn* [])))
            (.start))))))

83x faster than current implementation 
```
(run-benchmark
  (fn []
    (testing "`promesa.exec.csp` implementation"
      ;; 4.956172 µs — this is due to `promesa.exec/wrap-bindings`'s way of forwarding
      ;; bindings, which is 83x slower than `clojure.core/binding-conveyor-fn`
      (criterium/bench
        (csp/go))
      ;; 4.889489 ms
      (criterium/bench
        (dotimes [i 1000]
          (csp/go))))
    (testing "Bare implementation"
      ;; 59.033042 ns
      (criterium/bench
        (-> (Thread/ofVirtual)
            (.unstarted (fn []))
            (.start))))
    (testing "With bindings forwarding"
      ;; 58.851215 ns
      (criterium/bench
        (-> (Thread/ofVirtual)
            (.unstarted (binding-conveyor (^{:once true} fn* [] ~@Body)))
            (.start))))))
```
This is what `clojure.core/future` does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant