Keep in mind that ocamlopt is pretty good at keeping int32 (and int64 on 64-bit platforms) unboxed within a function. This slightly contrived function, for example, reads the parameter from memory once, does all the arithmetic in registers and then allocates to return the new int32.
Furthermore, you can:
- Control inlining on a caller or callee basis with annotations: OCaml - Optimisation with Flambda
- Use
Bytes.{set,get}_int32_le
to store multiple int32s unboxed inbytes
(variants without bounds checks are available as externals)