-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Stack overflow" exception in JavaScript execution mode (with Js_of_ocaml) #138
Comments
I believe that exception-raising is also fairly slow with js-of-ocaml, so I suspect that the version you propose could be a noticeable performance regression for small lists. |
The performance regression mainly depends on the number of lists. Of course, if these lists are small it is more noticeable. I looked at this implementation :
It seems to be ok with my example (no stack overflow), but I wasn't able to extract its javascript translation since the debugger shows me only my Ocaml source code ! |
Yes; what you did is to inline the implementation of Note: what we learned here is that common monadic-programming idioms (recursive functions with bindings inside) are not properly supported by js_of_ocaml. I wondered if this may be a problem as well for the code generated by ppx_deriving_yojson. |
I moved my latest implementation in a part where I can see the javascript translation :
That looks safe since there is no recursion into the generated code! |
I asked above if you would be willing to send a Pull Request to implement the change. (Is this an implicit way to decline the invitation?). I think that a PR is nicer than a maintainer doing the change, in particular as it directly tracks authorship of the contribution. |
I would have greatly preferred to let the authorship of that inline to the compiler! |
Within the JavaScript mode the compilation of the recursive functions is not optimized (c.f. http://ocsigen.org/js_of_ocaml/3.7.0/manual/tailcall).
There is the Javascript translation of your
Ppx_deriving_yojson_runtime.map_bind
function :So, the conversion of a
Yojson.Safe.t
data into a long list of elements (~10.000) could raise aStack overflow
exception.Notice that kind of implementation (without
acc
) solves the problem:Of course, the proposed implementation can certainly be improved since the type of that
save_map_bind
function is less generic than yourmap_bind
function (but it seems to me that the proposed implementation is compliant with the.mli
interface except about the removed accumulator).The text was updated successfully, but these errors were encountered: