Some comments about optimization in OCaml.
In OCaml, I noticed that tuples always stand out when passing them as an argument. Even if the allocation in the primary heap happens quickly in ocaml, this is of course more than doing nothing. Thus, every time you pass a tuple as an argument, it takes some time to distribute and populate the tuple.
I was expecting the ocaml compiler to optimize cases where there is no need to build a tuple. For example, when you embed a called function, you can use only the components of the tuple, not the tuple itself. Thus, the tuple can simply be ignored. Unfortunately, in this case, OCaml does not delete the useless tuple and still performs the selection. For this reason, it is not recommended to use tuples in critical sections of code.
source share