OCaml Flambda: Desired Explicit Inline Size Threshold
25.6K reputation · 11 Apr 2025, 11:16 UTC
The Flambda optimization pipeline (enabled with -flambda) decides whether to inline a function using an internal heuristic that estimates function size and call‑site cost, but the exact size threshold is not exposed as a compiler flag. Developers would like to specify a maximum inline size so they can predict which functions will be inlined and avoid surprising performance regressions when minor changes alter the heuristic’s estimate.
Because the heuristic is undocumented and may evolve between releases, relying on it for performance‑critical code can lead to version‑specific behavior; a tiny edit such as adding a debug print can shift a function across the hidden threshold and cause measurable slowdowns. Although OCaml maintainers have discussed adding a tunable parameter similar to GCC’s -finline-limit, no agreement has been reached on its default value, interaction with existing -inline/-noinline flags, or the release cycle in which it should appear.
What numeric value should serve as the default inline size threshold? How should the new flag interact with -inline and -noinline to override or complement the heuristic? Which OCaml version should first expose this flag, and what backward‑compatibility guarantees are needed for existing build scripts?