Comments (8)
Thinking about this and #9 , what do you think will be the effects of missed branch predictions on this code? Can we engineer a test case where branch prediction isn't possible to test its effects?
from clj-fast.
I'm no expert on that, let alone knowing how engineer good degenerate cases. I guess you would have random input over the cases....no idea beyond that.
from clj-fast.
I ran the following interesting test:
(defn foo [k]
(fast-case k :a 0 :b 1 :c 2 :d 3 :e 4 :f 5 :g 6 :h 7 :i 9 :j 10 :k 11 :l 12 :m 13 :n 14 :o 15 :p 16 :q 17 :r 18 :s 19 :none))
(defn bar [k]
(case k :a 0 :b 1 :c 2 :d 3 :e 4 :f 5 :g 6 :h 7 :i 9 :j 10 :k 11 :l
12 :m 13 :n 14 :o 15 :p 16 :q 17 :r 18 :s 19 :none))
(def ks [:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :none])
(def lots (repeatedly 10000 #(rand-nth ks)))
(do
(c/bench (doseq [k lots] 0))
(c/bench (doseq [k lots] (foo k)))
(c/bench (doseq [k lots] (bar k))))
Overhead: 571.822473 µs
Fast case: 654.098578 µs, minus overhead 85
Core case: 740.666878 µs, minus overhead 170
=> fast case is 2x faster, amortized .
from clj-fast.
Nice. I tend to use case quit a bit, as does some clojure internals like defrecord, so this seems generally useful.
from clj-fast.
I wander how critical it actually is. While identity case checks are 2x faster we're still talking about 4 vs 8 ns in the worst case scenario, not to mention I did not measure these influences in a wider context of a running application. Perhaps cache misses will degrade other parts' characteristics, so I'm still wary.
It would be interesting to get a profile of a typical application and how many times it cases on keywords.
from clj-fast.
If you're using keyword access for records, it will impact your performance. Ended up being a enough in the IFCPC optimization case (where I first ran into this, and defrecord's weaker performance compared to arraymaps..) that I found out about this. If you're not using idiomatic paths that leverage case
on hot paths, it may not matter then. That can probably be applied to most of these optimizations though (e.g. context and profiling matter).
from clj-fast.
Is there a need to introduce the binding to ge
and type hint it as an Object? I fail to see the ratilnale behind it. Am I missing anything?
from clj-fast.
That came from the original source in clojure.core/case. Unsure.
from clj-fast.
Related Issues (20)
- Faster fast-merge HOT 47
- better memoize example HOT 13
- Better get-in behavior (maybe already implemented) HOT 6
- May not be in scope, but fast detection of set intersection
- static-merge HOT 2
- fastrecord HOT 10
- Clojurescript support? HOT 2
- make sure inlining is wrapped in a function that can be jit'd HOT 4
- Operations on ordered collections (probing) can be faster HOT 6
- Array cloning performance diffs HOT 25
- faster mapv and others (reference) using iterators HOT 2
- FileNotFoundException when try to use clj-fast HOT 2
- Extend assoc-in to take multiple k-v pairs? HOT 4
- not-found arities of get and get-in HOT 2
- General inliner HOT 11
- JMH
- Improve documentation and guidance
- faster aset HOT 2
- Bug in update-many
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clj-fast.