Fork me on GitHub
#clojure-europe
<
2020-11-26
>
dharrigan07:11:10

Good Morning!

plexus07:11:18

Good morning!

ray08:11:21

was thinking about the overhead of hashes last night, as you do

dominicm08:11:18

What kinds of hash do you have problems with @raymcdermott?

ray08:11:01

(doseq [_ (range 5)]
  (time (let [sha (MessageDigest/getInstance "SHA-256")]
          (count (map (fn [x]
                        (->> x (.digest sha)))
                      (take 1000000 (repeatedly #(.getBytes (str "HASH" (rand-int Integer/MAX_VALUE))))))))))
"Elapsed time: 380.187311 msecs"
"Elapsed time: 376.734624 msecs"
"Elapsed time: 377.796685 msecs"
"Elapsed time: 378.096179 msecs"
"Elapsed time: 377.964661 msecs"
=> nil
(doseq [_ (range 5)]
  (time (let [sha (MessageDigest/getInstance "SHA-256")]
          (count (map (fn [x]
                        (->> x (.getBytes) (.digest sha)))
                      (take 1000000 (repeatedly #(str "HASH" (rand-int Integer/MAX_VALUE)))))))))
"Elapsed time: 1509.481255 msecs"
"Elapsed time: 1510.545895 msecs"
"Elapsed time: 1476.821262 msecs"
"Elapsed time: 1480.023988 msecs"
"Elapsed time: 1469.693934 msecs"

ray08:11:27

placement of .getBytes makes a huge performance difference

ray08:11:04

1m hashes in 380ms or 1500ms

ray08:11:13

thoughts?

Ben Hammond08:11:39

could it be reflection kicking in? maybe try a few type hints?

ray08:11:10

you're right, type hints FTW - it could see it after str but not in the function. Great spot - thanks!

๐Ÿ‘ 6
ray08:11:29

but also, I see your ๐ŸŒฟ joke there @dominicm ...

ray08:11:52

@val_waeselynck re nginx from the other day ... using a cache like Varnish is often better if you have static assets cos then you don't need to split up your thinking between static and dynamic processing

๐Ÿ‘ 3
ray08:11:09

I think of like memoize at a system level

slipset08:11:05

@raymcdermott As @ben.hammond suggested, type hints solves the problem:

(doseq [_ (range 5)]
  (time (let [sha (MessageDigest/getInstance "SHA-256")]
          (count (map (fn [^String x]
                        (->> x (.getBytes) (.digest sha)))
                      (take 1000000 (repeatedly #(str "HASH" (rand-int Integer/MAX_VALUE)))))))))

ray08:11:58

and a :face_palm::skin-tone-3: for me ๐Ÿ™‚

slipset08:11:08

BTW, WTF were you doing replying in a thread @raymcdermott?

ray08:11:29

it's Ben, he gets a pass

ray08:11:38

also I allow myself to be inconsistent and hypocritical

Ben Hammond08:11:44

oh? are threads contraversial?

dominicm08:11:47

Yeah, we don't like 'em round here. They unravel too easily.

ray09:11:02

Too many clicks for my liking but no rules

simongray09:11:22

I like threadsโ€ฆ ๐Ÿ˜•

dharrigan09:11:36

Threads vs No Threads reminds me of the noble tradition of Spaces vs Tabs and Emacs vs Vim ๐Ÿ™‚

๐Ÿ˜„ 6
Ben Hammond09:11:47

hunter-gatherers vs farmer-herders

ray09:11:42

Threads are the type system of Slack

dominicm09:11:45

If you review the Richligious texts, you'll see he's very clearly against all forms of braiding. That includes threads!!!!!!!one!

simongray09:11:21

@dominicm Keeping different discussions in different threads is clearly more decomplected than mixing all the topics together in the channel :P

dominicm09:11:05

To be fair, threads don't accurately mirror conversation. They mimic it, like a child playing with a toy oven. Conversations do more than simply splinter. They repeatedly splinter, and then they converge. They're far more like a git commit history.

ray09:11:41

Oh Jesus

borkdude13:11:53

Since you were discussing threads, I thought I would put in some multi-threaded printing. ng.

otfrom13:11:41

yep, my dumb logging does that (if I don't use tap>)

ray14:11:56

apropos threads: the first person to say fractal is gonna get it, right between the parens

mpenet14:11:59

why the fractal hate?

otfrom14:11:07

is it really pretty in an unexpectedly mathematical way?

otfrom14:11:17

this feels like a real problem given your status

otfrom15:11:39

may the parens of โค๏ธ protect us all from hate ๐Ÿ™‚

ray16:11:52

( hehe )