Skip to content
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

Remove unnecessary #[inline] hints #3867

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

daxpedda
Copy link
Member

As discussed in the last meeting, this PR removes unnecessary #[inline] hints, which hurt compile times and sometimes even performance.
To summarize:

  • Adding #[inline] to generic functions is not recommended.
  • Adding #[inline] to non-public functions is not recommended.
  • Adding #[inline] to public functions because they only call a private function is not recommended, unless that private function is small and is annotated with #[inline] as well.

#[inline] should only be used for small non-generic public functions or after some benchmarking.

See https://matklad.github.io/2021/07/09/inline-in-rust.html and rust-lang/hashbrown#119 (comment) for more detailed information and recommendations.

@daxpedda daxpedda added the S - enhancement Wouldn't this be the coolest? label Aug 14, 2024
@MarijnS95
Copy link
Member

Fwiw, in ash, we added #[inline] to all our public "high-level" wrapper APIs that wrap public "sys-like" APIs, and got quite a compile-time performance boost out of it: ash-rs/ash#602 (comment) / ash-rs/ash#638

So I hope you're leaving public functions that call public functions/constructors in place?

Comment on lines -160 to 159
#[inline]
pub fn cast<X: Pixel>(&self) -> LogicalUnit<X> {
LogicalUnit(self.0.cast())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small public function calling public code? All of these, it seems like?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emphasis on non-generic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wake up and try reading this again after a few hours 🙈.

@daxpedda
Copy link
Member Author

daxpedda commented Aug 14, 2024

So I hope you're leaving public functions that call public functions/constructors in place?

Yes!
Let me know if I missed any.

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. that's a lot of #[inline] that we've been using

Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep my approval.

Will just like to hold it until we merge like big PRs, since this one was pretty much done automatically(I hope so) and can be regenerated when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S - enhancement Wouldn't this be the coolest?
Development

Successfully merging this pull request may close these issues.

4 participants