ffi_call_plan caching for GLib

Lobsters Hottest Tools

Summary

GLib adopts libffi's new ffi_call_plan caching to reduce GClosure invocation overhead by 10-25%, with merge request submitted and frame-pointer patches for profiling.

<p><a href="https://lobste.rs/s/jw5a02/ffi_call_plan_caching_for_glib">Comments</a></p>
Original Article
View Cached Full Text

Cached at: 07/24/26, 07:05 PM

# ffi_call_plan caching for GLib Source: [https://blogs.gnome.org/chergert/2026/07/24/ffi_call_plan-caching-for-glib/](https://blogs.gnome.org/chergert/2026/07/24/ffi_call_plan-caching-for-glib/) [Skip to content](https://blogs.gnome.org/chergert/2026/07/24/ffi_call_plan-caching-for-glib/#content) About a month ago[Anthony Green](https://atgreen.github.io/repl-yell/)added a novel “call plan” to[libffi](https://github.com/libffi/libffi)\. This allows one to cache the hard work of determining what to do once and skip all of that work in subsequent calls\. You can read more of the details[on their article about it](https://atgreen.github.io/repl-yell/posts/libffi-plan-cache/)\. The best case for me was about a 25% reduction in amortized overhead for`GClosure`invocation\. In some less ideal situations it was still about a 10% reduction\. Not bad\! A[merge request for GLib is here](https://gitlab.gnome.org/GNOME/glib/-/merge_requests/5256), though it will likely require some build system triage since it requires the newest libffi for CI to unblock it\. I also[patched`libffi`to add frame\-pointers](https://gitlab.gnome.org/-/snippets/7847)so I can unwind across ffi boundaries from the Linux perf unwinder\. Very handy if you want, you know, to profile your system in a useful manner\. And repeated testing here showed about the same \(or shockingly less\) overhead than the counter\-parts\. Modern CPU sure are interesting beasts\. ## Post navigation

Similar Articles

Performance improvements in libffi

Lobsters Hottest

This article details a performance improvement in libffi, where caching argument placement as a flat list of moves (a 'plan') eliminates redundant reclassification on every function call, offering significant speedups without resorting to JIT compilation.

The Fil-C Optimized Calling Convention

Hacker News Top

The Fil-C optimized calling convention ensures memory safety for C programs even under adversarial misuse, while maintaining efficiency by omitting safety checks in the common case. It explains the generic and register-passing optimizations that handle type violations via panics or well-defined behavior.

Tail-call optimization in C is relatively recent

Hacker News Top

A LWN comment discusses the relatively recent implementation of tail-call optimization in C compilers, citing historical limitations and noting that modern GCC and Clang now support it, with potential benefits for interpreter implementations.

Fil-C: Garbage In, Memory Safety Out

Lobsters Hottest

Fil-C is a fully memory-safe implementation of C/C++. It bundles pointer values with boundary information using invisicaps at the LLVM IR stage, achieving high compatibility with a performance penalty of about 4x.