Tips for optimizing OCaml code.
NOTE: This is a Work In Progress post, I'll update this as I learn more.
- Try to reduce
- Reduce allocations, avoiding something like
'a optioncan help with performance quite a lot.
- Use higher order functions sparingly. For example: see here. That kind of goes on to show the cost of indirect calls(which means inlining can't possibly happen)
- Looking into the assembly generated is your friend. Link which tells you how to do that
- This Profiling section for ocaml.org and Compiler Backend section Real World OCaml gives overview of profiling and some information on generated assembly.
- Useful links for knowing more about internals : 1, 2