Object style code, how to avoid GC pressure?
I have a bunch of functions of the form: state -> params -> state, where state is a record. After profiling I realized that 50% of cycles in that region are spent in GC. I guess Ocaml can't tell it is safe to reuse the record and keeps allocating new ones. One option would be to make the record fields mutable, however I would prefer to keep the code pure.
Is there any other way to restructure the code to avoid the allocations?
Posted Aug 4, 2021, 12:54 PM UTC · edited
Pooling maybe a solution, but it involves Obj.magic and friends. See Jane Street's core library for nice examples.
Tuple_pool, right? It seems like a viable solution, thank you for the suggestion :)