core-async

Yehonathan Sharvit 2019-07-12T15:16:14.266200Z

Any idea why thread is slower than go blocks

Yehonathan Sharvit 2019-07-12T15:16:15.266400Z

?

Joe Lane 2019-07-12T15:19:12.266800Z

Grab a copy of yourkit and profile it.

alexmiller 2019-07-12T16:05:42.268400Z

That is a meaningless question

Yehonathan Sharvit 2019-07-12T16:16:42.268700Z

@alexmiller what am I missing?

alexmiller 2019-07-12T16:17:20.269300Z

Everything? I’m not even sure where to start

alexmiller 2019-07-12T16:20:59.271100Z

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

Yehonathan Sharvit 2019-07-12T16:22:01.273200Z

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

alexmiller 2019-07-12T16:22:04.273300Z

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

Yehonathan Sharvit 2019-07-12T16:22:13.273500Z

I know that

Yehonathan Sharvit 2019-07-12T16:22:24.274Z

My purpose is didactic

alexmiller 2019-07-12T16:22:37.274600Z

Then start from a meaningful problem

Yehonathan Sharvit 2019-07-12T16:23:01.274800Z

I did that

alexmiller 2019-07-12T16:23:16.275400Z

What is it?

Yehonathan Sharvit 2019-07-12T16:23:38.275800Z

Writing in parallel to a db

alexmiller 2019-07-12T16:24:12.276700Z

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

Yehonathan Sharvit 2019-07-12T16:24:35.277200Z

I know

alexmiller 2019-07-12T16:25:06.278100Z

I don’t know how to help you

Yehonathan Sharvit 2019-07-12T16:25:09.278300Z

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

alexmiller 2019-07-12T16:26:49.280700Z

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

➕ 2
souenzzo 2019-07-12T17:35:58.281800Z

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.