I\'ve often read that exceptions are somewhat slow and should be avoided if performance is an issue (for instance, in Java, F#, etc). Does that apply to common OCaml functio
I've often read that exceptions are somewhat slow and should be avoided if performance is an issue (for instance, in Java, F#, etc). Does that apply to common OCaml functions such as Hashtbl.find, which return exceptions for elements not found?
No. Folklore around exceptions being slow and for exceptional circumstances in mainstream languages is nonsense. Exceptions are just another control flow construct. OCaml's exceptions are fast and commonly used for non-exceptional circumstances. Last I looked (a few years ago) exceptions were around 6x faster in OCaml than C++, around 100x faster than Java and around 600x faster than .NET.
People sometimes avoid exceptions in OCaml not for performance-related reasons but because they want explicit local control flow, typically forcing the caller to match
over a success/failure union type instead of potentially non-local exception propagation. They do this to improve correctness, which is more important than performance.