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

could JIT can inline closure Action? #34634

Closed
egmkang opened this issue Apr 7, 2020 · 5 comments
Closed

could JIT can inline closure Action? #34634

egmkang opened this issue Apr 7, 2020 · 5 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@egmkang
Copy link

egmkang commented Apr 7, 2020

void Foreach(Action<int> fn)
{
    foreach(var item in list)
    {
        fn(item);
    }
}

void test()
{
    var sum = 0;
    Foreach((item) => sum += item);
}

in the test function, call Foreach function will new a small object closure.

can CoreCLR JIT Engine inline this simple closure call?

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Apr 7, 2020
@omariom
Copy link
Contributor

omariom commented Apr 7, 2020

Theoretically, if JIT inlines call to Foreach at a particular callsite, it could find that the delegate points to a closure, get rid of the closure allocation, inline the call and "inline" the closure's fields as local variables.

@EgorBo
Copy link
Member

EgorBo commented Apr 7, 2020

Theoretically, if JIT inlines call to Foreach

Methods with loops never inline, they simply don't pass this check:

else if (!m_IsForceInline && (basicBlockCount > MAX_BASIC_BLOCKS))
{
SetNever(InlineObservation::CALLEE_TOO_MANY_BASIC_BLOCKS);
}

(well, if [AgressiveInlining] is not set of course)

@sakno
Copy link
Contributor

sakno commented Apr 7, 2020

Related to #6498

Methods with loops never inline, they simply don't pass this check:

Author asked about inlining of delegate invocation inside of this method.

@AndyAyersMS
Copy link
Member

Methods with loops never inline

Are you sure? Simple loops can have 5 or fewer BBs.

can CoreCLR JIT Engine inline this simple closure call?

Following up on what @sakno said, there are some notes on what it would take to inline a delegate invoke starting at this comment, and a number of issues to sort through before we're anywhere close to being able to do this.

@BruceForstall BruceForstall added this to the Future milestone Apr 7, 2020
@BruceForstall BruceForstall removed the untriaged New issue has not been triaged by the area owner label Apr 7, 2020
@jkotas
Copy link
Member

jkotas commented Apr 7, 2020

Duplicate of #6498 and #4584

@jkotas jkotas closed this as completed Apr 7, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

8 participants