-
Notifications
You must be signed in to change notification settings - Fork 139
Description
Motivation
Having read the guidelines on inlining (highly recommended for everyone!), I've understood that adding #[inline] explicitly is required to allow inlining across crates.
Even with recent rustc enhancements (related PR), the inlining policy is very conservative at the moment - requires that an (already optimized) function subject to cross-crate inlining does not contain any asserts nor calls.
Problem
scylla-cql crate's functions are largely short ones and, at the same time, are heavily called by scylla crate's routines.
Suggestion
Adding #[inline] to scylla-cql short functions (as already done in e.g. recently added RowSerializationContext) can bring considerable performance benefits on the ser/de code path.
Additionally, we can think about small functions in scylla that could make the driver's users benefit from their inlining.
Note
Do not forget that #[inline] requires transitivity. In the following code:
fn foo(x: i32) -> i32 {
x * 2
}
#[inline]
pub fn bar(x: i32) -> i32 {
foo(x) + 1
}if bar is called from another crate, it won't be inlined (however, IIUC, it's probable that the call to foo() will be inlined into bar body).
In order to enable inlining bar(), it is mandatory* that both foo and bar functions are marked with #[inline].
*not necessarily after the mentioned recent changes to rustc.