Aggressive inlining (+20% serialization speed boost) #147
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a roughly 20% speed improvement to serialization in my application benchmarks.
The use of
#[inline(always)]
is required because LLVM sees the function as "large" and avoids inlining a plain#[inline]
hint. However, almost all usage of these methods in ciborium specify the enum at compile-time, which means this "large" function can be optimised to a small set of instructions and remove many branches.I could add a
ciborium-bench
crate into the workspace using criterion to demonstrate this if this change is likely to be accepted? Cheers!One minor concern is compiling with opt_level
s
orz
, where application developers may prefer a smaller bundle size (such as WASM use cases). We could use asmaller-bundle
feature flag for this case, and use#[cfg_attr(not(feature = "smaller-bundle"), inline(always)]
instead. The binary bloat is likely minor though.