Why isn't OCaml recording bactrace by default

TL;DR; Backtrace recording has some performance impact, especially on code that uses them heavily, which used to be the default style in OCaml.

When you’re using Base or Core, it is enabled by default. In vanilla OCaml, it is indeed disabled by default, because it will affect performance in the exception-heavy code, and the default style in OCaml (if such exists) is to use exceptions a lot. OCaml is moving away from it, for example, the Janestreet style prefers ADT to exceptions, that’s why the exceptions could be enabled in Base and Core without a noticeable impact on performance. As an anecdote, my first big project in OCaml (it was 3.11) that was written in the style of that epoch, did have a noticeable performance impact when backtrace recording was enabled, so I had to disable them manually after I switched to Core. My current project doesn’t raise exceptions much so there is no difference in performance.

6 Likes