-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark libserialize functions as inline #53393
Conversation
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
Nice find. Looks good to me if the benchmarks are corroborated. |
⌛ Trying commit e59ea2fc56ef72b3ac332ccd28310d0662a186c0 with merge e895c391336eabdd2ec4d9f4c94a45c94f6902b0... |
src/libserialize/serialize.rs
Outdated
fn decode<D: Decoder>(d: &mut D) -> Result<Box<[T]>, D::Error> { | ||
let v: Vec<T> = Decodable::decode(d)?; | ||
Ok(v.into_boxed_slice()) | ||
} | ||
} | ||
|
||
impl<T:Encodable> Encodable for Rc<T> { | ||
#[inline] | ||
#[inline] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearly this isn't my fault, as nobody made a lint for it!
src/libserialize/serialize.rs
Outdated
#[inline] | ||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { | ||
(**self).encode(s) | ||
} | ||
} | ||
|
||
impl<T:Decodable> Decodable for Rc<T> { | ||
#[inline] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:O
e59ea2f
to
bc900f5
Compare
Rebased.
|
@Mark-Simulacrum Could I get a perf run? Or are we waiting on making a dent in the queue? |
src/libserialize/collection_impls.rs
Outdated
@@ -20,6 +20,7 @@ use std::sync::Arc; | |||
impl< | |||
T: Encodable | |||
> Encodable for LinkedList<T> { | |||
#[inline] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought #[inline]
was unnecessary on generic methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, ever since multiple codegen units, it can matter. I forget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the discussion I remembered: #52704
@@ -193,6 +194,7 @@ impl<'a> Decoder<'a> { | |||
self.position += bytes; | |||
} | |||
|
|||
#[inline] | |||
pub fn read_raw_bytes(&mut self, s: &mut [u8]) -> Result<(), String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The #[inline]
s on things like this and write_signed_leb128
seem definitely good, though 👍
@rust-timer build e895c391336eabdd2ec4d9f4c94a45c94f6902b0 |
Success: Queued e895c391336eabdd2ec4d9f4c94a45c94f6902b0 with parent 5db71db, comparison URL. |
Looks like it's ready for r+ |
Thanks @scottmcm, I hadn't seen that thread. @alexcrichton can you tell whether any of the downsides of |
@dtolnay |
Thanks, we'll remove all the ones on generic functions. r? @dtolnay |
Done. I'd like to check perf again, just to be sure. |
@bors try |
⌛ Trying commit 1540e8c with merge 4c76652fddb127b9ed67aa60a665ab1d37f0e97f... |
☀️ Test successful - status-travis |
@rust-timer build 4c76652fddb127b9ed67aa60a665ab1d37f0e97f |
Success: Queued 4c76652fddb127b9ed67aa60a665ab1d37f0e97f with parent f34933b, comparison URL. |
Ah-ha! Interesting. Looks too consistently worse to e noise. |
@bors: r+ Ok I'm gonna go ahead and approve this because the functions tagged for inlining here are "obvious candidates for inlining". While it's true that not all the performance was recovered from inlining everything I think this is a good baseline to start from. I would personally prefer further analysis to figure out which functions actually need to be inlined instead of inlining all of them, which may be possible through diffing perf runs with everything inlined and without everything inlined (hottest functions at the top are likely the candidates to be inlined). I suspect you're right in that LLVM just actually needs an extra hint for some of the functions here to inline them. |
📌 Commit 1540e8c has been approved by |
…xcrichton Mark libserialize functions as inline Got to thinking: "what if that big pile of tiny functions isn't inlining as it should?" So a few `replace-regex` later the local perf run says this: <details> ![](https://i.imgur.com/gvdJEgG.png) </details> Not huge, but still a win, which is interesting. Want to verify with the real perf run, but I understand there's a backlog. I didn't notice any increase in compile time or binary sizes for rustc/libs.
Rollup of 17 pull requests Successful merges: - #53030 (Updated RELEASES.md for 1.29.0) - #53104 (expand the documentation on the `Unpin` trait) - #53213 (Stabilize IP associated constants) - #53296 (When closure with no arguments was expected, suggest wrapping) - #53329 (Replace usages of ptr::offset with ptr::{add,sub}.) - #53363 (add individual docs to `core::num::NonZero*`) - #53370 (Stabilize macro_vis_matcher) - #53393 (Mark libserialize functions as inline) - #53405 (restore the page title after escaping out of a search) - #53452 (Change target triple used to check for lldb in build-manifest) - #53462 (Document Box::into_raw returns non-null ptr) - #53465 (Remove LinkMeta struct) - #53492 (update lld submodule to include RISCV patch) - #53496 (Fix typos found by codespell.) - #53521 (syntax: Optimize some literal parsing) - #53540 (Moved issue-53157.rs into src/test/ui/consts/const-eval/) - #53551 (Avoid some Place clones.) Failed merges: r? @ghost
@bors retry r- |
Got to thinking: "what if that big pile of tiny functions isn't inlining as it should?"
So a few
replace-regex
later the local perf run says this:I didn't notice any increase in compile time or binary sizes for rustc/libs.