janestreet / base

Standard library for OCaml
MIT License
848 stars 124 forks source link

Use raise_without_backtrace in Map, Set #131

Closed greedy closed 2 years ago

greedy commented 2 years ago

The add function uses the Same exception to exit early and return the input set unchanged. The exception was being raised with plain raise which causes expensive stack walking to build a backtrace. Raising the exception with raise_notrace produces a nice performance improvement in programs where this function is not and without changing program semantics since the exception cannot escape the add function.

greedy commented 2 years ago

Update to use Exn.raise_without_backtrace and made the same improvement in a few more places

bcc32 commented 2 years ago

Thanks for the patch. We actually happened to make the same improvement internally but it hadn't been pushed to GitHub yet. I'll leave this issue open until the push happens.