Fork me on GitHub
#core-async
<
2019-07-12
>
Yehonathan Sharvit15:07:14

Any idea why thread is slower than go blocks

Joe Lane15:07:12

Grab a copy of yourkit and profile it.

Alex Miller (Clojure team)16:07:42

That is a meaningless question

Alex Miller (Clojure team)16:07:20

Everything? I’m not even sure where to start

Alex Miller (Clojure team)16:07:59

This code is nonsensical. Starting from an actual meaningful problem would be a good first step.

Yehonathan Sharvit16:07:01

I am trying to come up with a simple code snippet that demonstrates how go blocks work

Alex Miller (Clojure team)16:07:04

thread and go are for different purposes, and that is a more meaningful decision dimension than perf

Yehonathan Sharvit16:07:24

My purpose is didactic

Alex Miller (Clojure team)16:07:37

Then start from a meaningful problem

Yehonathan Sharvit16:07:38

Writing in parallel to a db

Alex Miller (Clojure team)16:07:12

We’ll go blocks shouldn’t block, so that’s a bad problem to demonstrate go blocks

Alex Miller (Clojure team)16:07:06

I don’t know how to help you

Yehonathan Sharvit16:07:09

Can you think of a simple way to demonstrate that go blocks don’t have a perfomance hit?

souenzzo17:07:58

Spawn threads is slower then "spawn" go blocks

(time 
  (dotimes [i 1e6]
    (async/go i)))
"Elapsed time: 476.882375 msecs"
=> nil
(time 
  (dotimes [i 1e6]
    (async/thread i)))
"Elapsed time: 1285.235322 msecs"
As Alex said, it isn't irrelevant, once they have different proposes and on both proposes, the performance implications arent related with "spawn" cost.

Alex Miller (Clojure team)16:07:49

Go blocks are a process and communication tool. They are about organizing the running parts of your program. Performance is not imo a concern that enters that equation

8