HomePhabricator

[OCaml] Minor optimizations by avoiding double initialization

Authored by jberdine on Mar 27 2021, 9:54 AM.

Description

[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

Details

Committed
jberdineApr 5 2021, 2:55 AM
Differential Revision
D99472: [OCaml] Minor optimizations by avoiding double initialization
Parents
rG5c25ff8739e0: [OCaml] Fix unsafe uses of Store_field
Branches
Unknown
Tags
Unknown