Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Why are monads so slow?

Name: Anonymous 2014-02-07 15:37

Why are monads so slow?

Just to get a taste of this Haskell fad, I conjured up this little benchmark:
http://pastebin.com/qgxnGaj6
It increments an integer ten thousand times in three different monads and then in a pure function.
First of all I must say that monad transformers are a bitch. It was really confusing to figure out what to lift, what not to lift, and in what order to unwrap them.
Second: I expected monad transformers to be slow, but I had hoped that at least the monads in GHC were optimized by now. After all, every Haskell program is a monad, how can you not make sure they're as tight as possible?


benchmarking Foo:
mean: 54.06153 us,
benchmarking Bar:
mean: 59.34639 us
benchmarking Baz:
mean: 392.4655 us
benchmarking Pure:
mean: 5.737042 us

The results are very dissatisfying. Monads are not only ugly and hard to work with, but they're also slow. IO-monadic code is approx. 10 times slower than pure code. Adding a StateT doesn't make things much worse, but a RWST more and your code is 6 more times slower, for a total of 60x slowdown over non-monadic code! Haskell is simply pathetic.

Name: Anonymous 2014-02-07 15:40

Name: Anonymous 2014-02-07 15:44

>>2
Meet Tesak, a kike who used to pose as an antisemite, then posed as an antipedophile, then as an anti-gay. A professional Jew fascist, in other words.
He was recently arrested on Cuba, by the way. I hope he rots in jail.

Name: Anonymous 2014-02-07 15:48

>>1`
>2015-1
>not embracing the monomorphism restriction

back to /g/

Name: Anonymous 2014-02-07 16:03

>>3
who's beating the faggot is irrelevant. The faggot got what he deserved. Kikes, sandniggers, niggers, everybody is welcome in this game.

Name: Anonymous 2014-02-07 19:30

Name: Anonymous 2014-02-07 21:48

Name: Anonymous 2014-02-08 12:25

Well, I've improved my program, adding another test for a pure computation with an ST mutable state inside:

http://ideone.com/xFLDoE

You can compile it with "ghc -O2 --make Main.hs" and then run with "./Make -t win -u res.csv".

The results are appalling. The ST monad, which was supposed to be all about mutable speed without any IO overhead, turned out to be even slower than IO!

IO                  51 us
IO with StateT      57 us
IO + StateT + RWST 352 us
Pure                 6 us
Pure with ST         199 us

That's about 33x slowdown just for using mutable state! Haskell is really amazing at avoiding success.

>>6
>>7
Those examples are about slow code that uses monads. My benchmark is about how all code that uses monads is slow, i.e. about the inevitable overhead of using monads.

Name: Anonymous 2014-02-08 12:45

Increased the number of iterations tenfold and the IO monad got 50 times slower! The monadic overhead has a larger than linear complexity! All of that without me using any complex control patterns or custom monads, just the standard library functions, monads and monad transformers.
Dang, Haskell was really created for idiots.

Name: Anonymous 2014-02-09 0:15

>>8
Supposedly, GHC 7.8 (RC) fixes a lot of IO overhead, especially for mulithreaded programs.

"avoid $ success at all costs"

Name: Anonymous 2014-02-09 5:57

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2014-02-09 7:19

Why is abstraction slow
Because it makes the CPU spend time executing a ton of unnecessary instructions.

Name: Anonymous 2014-02-09 12:24

>>1
Holy fuck that code is a clusterfuck. Literally what are you doing?

After all, every Haskell program is a monad,

Sounds like you don't know what a monad is.

Name: Anonymous 2014-02-09 12:25

>>13
Every Haskell program must contain a function "main" of type "IO a", IO is a monad, hence every Haskell program is a monad. He's right.

Name: Anonymous 2014-02-09 13:02

>>14
But not every monad is an IO monad. Under the hood, the IO data type is obviously treated differently than pure data types like Maybe.

Name: Anonymous 2014-02-09 13:04

You really should be bitching about the lazy IO not monads.

Name: Anonymous 2014-02-09 13:38

>>14
‘IO’ forms an instance of a monad given an appropriate definition of return and >>=. ‘IO a’ does not form an instance of a monad. ‘IO’ ≠ ‘IO a’. He's wrong. Also the main type is ‘IO ()’ which also makes you wrong.

Name: Anonymous 2014-02-22 21:32

Wow, Haskell is garbage.  Thank you for shining a light on this critical and under-reported issue, OP.

Name: Anonymous 2014-02-23 5:02

>>18
No, Haskell is king, and OP is a faggot.
A language without laziness is a language without abstractions.
A language without purity is a language where mutability and effects cannot be reasoned about.

Name: Anonymous 2014-02-23 12:34

>>19
Haha, look at this dumb who can't reason about mutable state!

Name: Anonymous 2014-02-23 13:06

>>19
purity
Shalom!

Name: Anonymous 2014-02-23 13:31

>>20
And neither can you, because it's imporrible. That's why imperative shit doesn't have any reasonable concurrency or parallelism.

Name: FORTRAN 2014-02-23 13:35

>>22
Hello there, my name is FORTRAN and I think that you are a little wrong sir, me and my sisters ada and Oz have very good concurrency and parallelism!
also as far as I know erlang, a language with very good concurrency is not pure!

Name: Anonymous 2014-02-23 14:47

>>23
Just whom do you think you're kidding here? Fortran uses OpenMP crap, Ada uses semaphores and Erlang doesn't have shared state.

I've actually whipped out a book on parallel Ada and finding proof that it is a piece of shit was a snap:

"""
When the task currently executing within the protected object completes the body of the protected procedure, it will leave the object and the read/write lock will become inactive. At that point one of the other tasks will start its desired operation and activate a lock. Which of those many delayed tasks is selected is not defined by the core language.
"""

"""
The two locks provide mutually exclusive read/write access and mutually exclusive read access to the data within the protected object. As tasks may be delayed by these locks, it is important to keep the code in the bodies of protected procedures and functions (the critical sections) as short as
possible. Locks do not provide any synchronization. It is possible, therefore, that a group of reader tasks executing protected functions can starve writer tasks wanting to execute protected procedures. One can imagine from Figure 4.2
the possibility of newly arriving reader tasks replacing departing reader tasks, delaying those tasks that need the read/write access provided by the protected procedures.
"""

Name: Anonymous 2014-02-23 15:01

>>24
Just whom do you think you're kidding here?
Ada allows message passing, most compilers for Fortran make automatic paralelisation and why should I care about shared state?

Name: 25 2014-02-23 15:03

I forgot to add that mutable state is not the same as shared state so >>24 is wrong

Name: Anonymous 2014-02-23 15:07

>>26
Obviously, mutable shared state is what the problem of concurrency is about. If the state is immutable, or not shared, then there is no problem, but that's not a solution, just an evasion..

Name: Anonymous 2014-02-23 15:30

>>27
In erlang there is mutable state but there is not shared state (actor models is awesome!), so there is not really a problem

Name: sage 2014-02-23 17:56

>>22
concurrent ml is pretty reasonable :'(

Name: oh my god 2014-02-23 17:57

i typed sage in the wrong box guys

Name: Anonymous 2014-02-23 18:01

>>29-30
>le pedophile fail sage

Name: Anonymous 2014-02-23 20:38

>>22
Look, it's simple. You have a variable, and you update it, and now it has a different value. Kid's level stuff.
Then you fire up a couple of threads, and boom! Concurrency and parallelism!

Don't change these.
Name: Email:
Entire Thread Thread List