Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7737205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:56:14+00:00 2026-06-01T07:56:14+00:00

I mostly develop using C#, but I think this question might be suitable for

  • 0

I mostly develop using C#, but I think this question might be suitable for other languages as well.
Also, it seems like there is a lot of code here but the question is very simple.

Inlining, as I understand it, is the compiler (in the case of C# the Virtual Machine) replacing a method call by inserting the body of the method in every place the method was called from.

Let’s say I have the following program:

static Main()
{        
    int number = 7;
    bool a;
    a = IsEven(number);
    Console.WriteLine(a);
}

… the body of the method IsEven:

bool IsEven(int n) 
{
    if (n % 2 == 0) // Two conditional return paths
        return true;
    else
        return false;
}

I could understand how code will look like after inlining the method:

static Main()
{
    int number = 7;
    bool a;
    if (number % 2 == 0)
        a = true;
    else
        a = false;
    Console.WriteLine(a); // Will print true if 'number' is even, otherwise false
}

An obviously simple and correct program.

But if I tweak the body of IsEven a little bit to include an absolute return path…

bool IsEven(int n)
{
    if (n % 2 == 0)
        return true;
    return false; // <- Absolute return path!
}

I personally like this style a bit more in some situations. Some refractoring tools might even suggest that I do change the first version to look like this one – but when I tried to imagine how this method would look like when it’s inlined I was stumped.
If we inline the second version of the method:

static Main()
{
    int number = 7;
    bool a;
    if (number % 2 == 0)
        a = true;
    a = false;
    Console.WriteLine(a); // Will always print false!
}

The question to be asked:
How does the Compiler / Virtual Machine deal with inlining a method that has an absolute return path?
It seems extremely unlikely that something like this would really prevent method inlining, so I wonder how such things are dealt with. Perhaps the process of inlining isn’t as simple as this? Maybe one version is more likely to being inlined by the VM?

Edit:
Profiling both methods (and manual inlining of the first one) showed no difference in performance, so I can only assume that both methods get inlined and work in the same or similar manner (at least on my VM).
Also, these methods are extremely simple and seem almost interchangeable, but complex methods with absolute return paths might be much more difficult to change into versions without absolute return paths.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:56:15+00:00Added an answer on June 1, 2026 at 7:56 am

    It’s can be kind of hard to explain what the JITter does when it inlines – it does not chage the C# code to do the inlining – it will (always?) work on the produced bytes (the compiled version) – and the “tools” you have when producing assembly-code (the actual machine code bytes) are much more fine grained than what you have in C# (or IL for that matter).

    That said, you can have an idea of how it works, in C# terms by considering the break keyword..

    Consider the possiblity that every inline function that’s not trivial is enclosed in a while (true) loop (or do while(false) loop) – and that every source return is translated to a localVar = result; break; set of statements. Then you get something like this:

    static Main() 
    { 
        int number = 7; 
        bool a; 
        while (true)
        {
           if (number % 2 == 0) 
           {
              a = true; 
              break;
            }
            a = false; 
            break;
        }
    
        Console.WriteLine(a); // Will always print the right thing! Yey!
    }
    

    Similarly, when producing assembly, you will see A LOT of jmps being generated – those are the moral equivalent of the break statements, but they are MUCH more flexible (think about them as anonymous gotos or something).

    So you can see, the jitter (and any compiler that compiles to native) has A LOT of tools at hand it can use to do “the right thing”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using mostly GCC to develop my library, but I'd like to ensure cross-compiler
I'm using symfony to develop a website and have it mostly functioning, but I
I mostly develop in PHP, but I'm using Python and Ruby more and more.
We develop mostly low traffic but highly specialized web applications. Normally we use L2S,
I want to develop an authentication module using PAM, but I'm having trouble getting
I know, this has been asked a few times, but mostly for Xcode 3.x.
Is there a languages other then Java to develop native apps in android without
I am using Hibernate and mySQL. I develop the java application mostly on windows.
I mostly use lambda functions but sometimes use nested functions that seem to provide
Having mostly worked with C#, I tend to think in terms of C# features

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.