Skip to content

[mono] Optimize box+callvirt to direct call #32166

Closed

Description

@EgorBo
public class C 
{
    static void Foo1(MyIterator i) => i.Dispose();
    static void Foo2(MyIterator i) => ((IDisposable)i).Dispose();
}

public struct MyIterator: IDisposable
{
    public void Dispose()
    {
        // in 99% cases iterators have empty Dispose()
    }
}

Both Foo1 and Foo2 should be empty in the final codegen, but unfortunately in mono the Foo2 emits a lot of boilerplate codegen due to unoptimized boxing.

This is one of the reasons why mono emits a lot of redundant codegen for foreach statements (the finally block).

Mono should optimize box + callvirt just like coreclr does:

// If it is a value class, mark the "box" node. We can use this information
// to optimise several cases:
// "box(x) == null" --> false
// "(box(x)).CallAnInterfaceMethod(...)" --> "(&x).CallAValueTypeMethod"
// "(box(x)).CallAnObjectMethod(...)" --> "(&x).CallAValueTypeMethod"

Activity

  1. added
    area-CodeGen-coreclr
    untriaged
    on Feb 12, 2020
  2. EgorBo commented on Feb 12, 2020

    @EgorBo
    MemberAuthor
  3. added and removed
    area-CodeGen-coreclr
    untriaged
    on Feb 12, 2020
  4. added this to the 6.0.0 milestone on Jun 22, 2020
  5. modified the milestones: 6.0.0, 7.0.0 on Jun 16, 2021
  6. naricc commented on Jul 21, 2022

    @naricc
    Contributor

    @ivanpovazan @jandupej I think we can move this to milestone .net8 unless there is a lot closer to done than I realize?

  7. ivanpovazan commented on Jul 21, 2022

    @ivanpovazan
    Member

    Yes, I think it can be moved to .net8

  8. modified the milestones: 7.0.0, 8.0.0 on Jul 21, 2022
  9. jandupej commented on Jul 22, 2022

    @jandupej
    Contributor

    @naricc I will need more time for this. I think we should move the issue, if possible.

  10. ghost locked as resolved and limited conversation to collaborators on Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions