Closed ncik-roberts closed 3 weeks ago
I'm surprised you can observe any difference. All of these functions are called in parts of the code that are evaluated once per class (not even once per class created at runtime, but once per class in the source code). So if you notice a difference with this PR, it means you're spending significantly more time creating classes than actually using them. I don't mind the PR though, I think options are better than exceptions for these cases anyway.
@lthls: In applications that are compiled to javascript via Js_of_ocaml, our benchmarks show that throwing and catching an exception can cost as much as 2ms. In a program that had three levels of inheritence on a 50-method class, we saw that over one second was spent throwing and catching exceptions in camlinternalOO.ml
at program startup time.
@lthls: In applications that are compiled to javascript via Js_of_ocaml, our benchmarks show that throwing and catching an exception can cost as much as 2ms. In a program that had three levels of inheritence on a 50-method class, we saw that over one second was spent throwing and catching exceptions in
camlinternalOO.ml
at program startup time.
That makes sense, thanks for the context.
Have you tried using OCamlClean https://github.com/bvaugon/ocamlclean ? It does partially evaluate bytecode programs. I know that it is supposed to be quite good with class initialisation. It has not been updated recently but you could at least try on your files to see if it reduces the size. Also it might not right away with JSOO.
We have some evidence that doing this will speed up uses of the object system in JSOO.
I don't see a compelling reason to use exceptions in
ocaml/stdlib/camlinternalOO.ml
, and think using options is fine. I don't think this will affect bytecode or native compilation meaningfully. Perhaps this will add some more short-lived allocations for uses of the object system, but I don't think it's meaningfully more, judging from the surrounding code.