A change in my library made it much slower. Profiling isn't helping me. What might be the reason for the slow-down?

喜你入骨 提交于 2019-12-05 02:44:51

According to the profiling report, most of the time is spent in hFlush and hGetSome. According to time, the slow version takes a lot more sys time. So, my hypothesis is that a lot of time is spent blocked and waiting, whether it's waiting for more input or locking and unlocking threads.

Here's the first thing I would do: compile the code with -threaded and see what happens. The threaded runtime uses a completely different IO manager, and I strongly suspect that this single change will fix your problem.

My guess would be that it's something to do with the overhead of Chan.

My first thought was increased GC time, but that doesn't appear to be the case at all. So my second thought is that maybe all the locking and unlocking involved in using Chan (which is implemented on top of MVar) is the problem. But this is still only a guess.

You might try TChan (i.e., STM) instead and see if that makes the slightest shred of difference. (Perhaps you could code up a small skeleton just to compare the two and see if that's where the problem is, rather than reimplement your "real" code.)

Other than that, I'm out of ideas.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!