Inline finaliziers - #55
Conversation
|
I think I initially wanted to avoid inline because internal methods like It is though strange than under LTO it wouldn't at least consider to optimize it on its own... I will give it some tests myself on this weekend to see how effective it is on my laptop |
|
That'd be my recommendation. It took embarrassingly many cycles to get a stable read on what LLVM does in different scenarios, but at the end it seems sufficiently stable that LLVM does use inline+dead-code-elimination opportunities, yet does not spill the guts of those functions everywhere |
|
I did some runs of my performance tests, but results were hardly consistent so I'm not sure if it was effect of is inlining Some samples: |
This encourages LLVM to inline
.digest()into the caller. Currently, while the comments explicitly refer to inlining, LLVM does not inline these methods for all cases I measured, but does with the attribute. Notice that#[inline]remains the weaker suggestion compared to#[inline(always)], but it brings us over the line (pun intended).Currently, LLVM does not actually take information from surrounding code into account. The benefit of adding
#[inline]therefor is mainly around theHasher-implementation or when not using the explicit one-shot path: LLVM will inline the entire thing into the caller when it then can aggressively remove all the state-handling, usually if the to-be-hashed value has a compile-time-known size. Hashing aTviaT: std::hash::HashwhereTisu64goes down by around -67% runtime,[u64; 4]down by -76%; similar small objects mostly the same; longer slices are mostly flat. Think ofHashMap<u64, ...>as a beneficiary.Inlining-changes are always somewhat opaque, so I encourage to benchmark yourself. I tested this change on AArch64 with Rust 1.81, 1.97, ThinLTO enabled/disabled, various codegen-unit settings, and - at least as far as the assembly goes - x86-64. The added hints consistently come with performance benefits especially around small-ish, constant-size objects; LLVM also does not over-aggressively inline e.g. for dynamic buffers. YMMV, but as far as I can see this is a win.