Demo of power of OCaml effects?

I just spent a day of my life learning about building dune / jsoo / effects – and after getting effects working, realized to my horror, that according to https://ocsigen.org/js_of_ocaml/latest/manual/performances , it might slow down my code up to a factor of 9.04 (worst case, bdd example).

Question: is there a concise example of the power of effects? I.e. side by side comparisons of simple code snippets of the form:

Solving X w/o Effects
Solving X with Effects

and ideally the latter looking far more elegant.

1 Like

To my understanding the big win with effects is enabling direct-style async I/O, this is demonstrated in the Eio library. The project readme has a great, comprehensive tutorial that walks through the main points.

To put it another way, the big win with effects is not that most devs would be using it directly, but rather that they would almost never need to.

3 Likes

In this particular case, I’m really after concrete comparisons. I feel like there should be a < 100 line snippet comparing w/ Effect vs wo/ Effect, showing how w/ Effect clearly wins.

What does win mean for you?
Eio shows you can have sane async I/O without monadic style programming, and you can compare it to lwt/async.
It’s a win in my book.

4 Likes

You should look at https://ocsigen.org/js_of_ocaml/dev/manual/performances which correspond to the master branch of jsoo. It include Effects: partial CPS transform by vouillon · Pull Request #1384 · ocsigen/js_of_ocaml · GitHub which greatly improve perf.

@hhugo : That looks impressive. Am I reading this correctly? Next release of jsoo --enable effects will have:

  • most cases: within 1%; some even faster
  • absolute worst case is within 20%

?

No. It says:

There is almost no speed impact for small monomorphic programs. We estimate that the slowdown will usually be below 30%, though it can be larger for code that heavily use higher-order functions and polymorphism (Lwt code, for instance).

I was looking at https://ocsigen.org/js_of_ocaml/dev/manual/files/performances/time-effects.png which shows everything below the 1.2 line.

Theses are all small monomorphic programs.

I understand that to you 20% vs 30% is a big difference. To me, they’re both amazing compared to the current worstcase of 10x (900%).

I understand that to you 20% vs 30% is a big difference.`

It is not my point. 30% is not a worst case slowdown. The slowdown can be higher’

Though it can be larger for code that heavily use higher-order functions and polymorphism (Lwt code, for instance).

In your experience, is the worstcase slowdown O(1), O(n) or O(2^n) ? I.e. can we construct some horrific function that forces the slowdown to blow up?

I don’t have enough experience with this. It was added very recently.