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

Use #[inline] everywhere. #145

Merged
merged 1 commit into from Apr 11, 2020
Merged

Use #[inline] everywhere. #145

merged 1 commit into from Apr 11, 2020

Conversation

m-ou-se
Copy link
Contributor

@m-ou-se m-ou-se commented Apr 11, 2020

I tried to follow the following rules for determining if something
should be #[inline]:

  • Functions that are trivial. (E.g. implementations of Add, or a
    trivial new function.)
  • Functions that do not appear trivial, but would generate trivial
    assembly. (E.g. functions with mostly Rust code that don't result much
    generated code: use statements, wrapping values, bit twiddling,
    #[cfg], PhantomData, etc.)
  • Functions that only call another function.
  • Functions that could benefit a lot from inline optimization:
    • Functions that have asserts/matches/ifs on the parameters, which are
      likely constant or known to be in a certain range:
      If a function starts with assert!(param < 32), inlining enables
      the compiler to completely optimize the check away if it already
      knows the value to always be less than 32.
      If a function matches on a parameter, inlining allows throwing all
      but one match arm away.
  • Functions where knowing the return value could benefit optimization on
    later calls/code.

I tried to follow the following rules for determining if something
should be #[inline]:

- Functions that are trivial. (E.g. implementations of `Add`, or a
  trivial `new` function.)
- Functions that do not appear trivial, but would generate trivial
  assembly. (E.g. functions with mostly Rust code that don't result much
  generated code: `use` statements, wrapping values, bit twiddling,
  `#[cfg]`, `PhantomData`, etc.)
- Functions that only call another function.
- Functions that could benefit a lot from inline optimization:
  - Functions that have asserts/matches/ifs on the parameters, which are
    likely constant or known to be in a certain range:
    If a function starts with `assert!(param < 32)`, inlining enables
    the compiler to completely optimize the check away if it already
    knows the value to always be less than 32.
    If a function matches on a parameter, inlining allows throwing all
   but one match arm away.
- Functions where knowing the return value could benefit optimization on
  later calls/code.
Copy link
Member

@phil-opp phil-opp left a comment

Thanks a lot for this! I have one small question about a removed inline, otherwise this looks good to me!

src/structures/paging/frame.rs Show resolved Hide resolved
@phil-opp phil-opp merged commit 855760e into rust-osdev:master Apr 11, 2020
5 checks passed
phil-opp added a commit that referenced this pull request Apr 11, 2020
@m-ou-se m-ou-se deleted the inline branch Apr 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants