Skip to content

Make small functions implicitly #[inline] #78120

Closed

Description

@jonas-schievink

It is very common to clutter libraries with #[inline] annotations on small/trivial functions to ensure that they optimize well. It shouldn't really be necessary to do this by hand so often. Instead, the compiler could use its inlining heuristic (which already exists for the MIR inliner) to decide when it is likely to be beneficial to make a function inlineable.

This was previously attempted in #70550

Activity

  1. added
    I-slowIssue: Problems and improvements with respect to performance of generated code.
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
    on Oct 19, 2020
  2. thomcc commented on Oct 23, 2020

    @thomcc
    Member

    I'd appreciate if there were a way to get the current behavior then — something between #[inline(never)] and #[inline]... Avoiding #[inline] can substantially improve compile times.

    That said supporting this complicates this issue.

  3. thomcc commented on Nov 4, 2020

    @thomcc
    Member

    I stand by what I said here — but at the same time I did just go through the (tedious) process of manually adding this to a crate that had very few #[inline] annotations in rusqlite/rusqlite#834

  4. jonas-schievink commented on Nov 4, 2020

    @jonas-schievink
    ContributorAuthor

    I wonder if doing this plus MIR inlining might not end up improving compile times. This is only about small functions, after all.

  5. mati865 commented on Mar 11, 2021

    @mati865
    Member

    What is the current status on this (or how to push it forward)?

    Looking at #70550 the MIR inliner seems to already have what it needs but it's not enabled yet.

  6. bjorn3 commented on Mar 12, 2021

    @bjorn3
    Member

    We do not currentlt store the MIR for non-#[inline] and non-generic functions in the crate metadata as necessary for inlining cross-crate.

  7. tmiasko commented on Nov 14, 2023

    @tmiasko
    Contributor

    Implemented in #116505.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-mir-opt-inliningArea: MIR inliningC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions