[OCaml] Minor optimizations by avoiding double initialization
In several functions an OCaml block is allocated and no further OCaml allocation functions (or other functions that might trigger allocation or collection) are performed before the block is fully initialized. In these cases, it is safe and slightly more efficient to allocate an uninitialized block. Also, the code does not become more complex after the non-initializing allocation, since in the case that a non-small allocation is made, the initial values stored are definitely not pointers to OCaml young blocks, and so initializing via direct assignment is still safe. That is, in general if `caml_alloc_small` is called, initializing it with direct assignments is safe, but if `caml_alloc_shr` is called (e.g. for a block larger than `Max_young_wosize`), then `caml_initialize` should be called to inform the GC of a potential major to minor pointer. But if the initial value is definitely not a young OCaml block, direct assignment is safe. Differential Revision: https://reviews.llvm.org/D99472
Loading
Please register or sign in to comment