473,657 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inline compilation across different assemblies?

I was wondering on the breadth of optimization with .NET JIT compiler.
Let's presume I have an assembly of static classes - mostly helper
functions. Some of these functions may be very small (small enough
that the optimizing compiler would inline them).

If I have another assembly that references this helper libary
assembly, could .NET's JIT compiler inline compile the usage of these
small helper functions?
Nov 15 '05 #1
6 2412
ThomasR <tr**********@e arthlink.net> wrote:
I was wondering on the breadth of optimization with .NET JIT compiler.
Let's presume I have an assembly of static classes - mostly helper
functions. Some of these functions may be very small (small enough
that the optimizing compiler would inline them).

If I have another assembly that references this helper libary
assembly, could .NET's JIT compiler inline compile the usage of these
small helper functions?


Having done a bit of testing, it doesn't *appear* that it can - at
least not as far as I can see.

I tested this by creating a helper class with two methods, one with
[MethodImplAttri bute(MethodImpl Options.NoInlin ing)] specified. This I
compiled into a library of its own.

I then create a second class which was much the same, but compiled it
along with the benchmarking app. Both methods took roughly the same
length of time for the "out of assembly" version, which was about the
same length of time as the non-inlined "in-assembly" version. The "in-
assembly" method which *was* inlined took significantly less time.

This is slightly worrying, I must admit...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
n!
> If I have another assembly that references this helper libary
assembly, could .NET's JIT compiler inline compile the usage of these
small helper functions?


Although I can't give a definitive answer, I would guess that yes it will
inline across assemblies. I say this as the MSIL is compiled to native
assembly by the JIT so there is really no reason for it not to.

Another reason is patly down to the article:
http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/highperfmanaged apps.asp which lists some of rules used by the JIT when it
is deciding whether to inline a method or not. Whilst the article explicitly
states that not all rules are presented, I would have thought
'cross-assembly' would be a significant rule (though once again, my
viewpoint may differ from the actual authors :).

You're not guaranteed a method is inlined however and the rules may change
in future revisions, so I wouldn't spend whole amounts of time worrying
about whether a method is lined or not until you start running into
performance problems with it :)

For a more insightful look into the JIT, the
microsoft.publi c.dotnet.framew ork.performance newsgroup may get you a more
in-depth and definitive answer.

n!
Nov 15 '05 #3
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
Having done a bit of testing, it doesn't *appear* that it can - at
least not as far as I can see.

I tested this by creating a helper class with two methods, one with
[MethodImplAttri bute(MethodImpl Options.NoInlin ing)] specified. This I
compiled into a library of its own.

I then create a second class which was much the same, but compiled it
along with the benchmarking app. Both methods took roughly the same
length of time for the "out of assembly" version, which was about the
same length of time as the non-inlined "in-assembly" version. The "in-
assembly" method which *was* inlined took significantly less time.


I've just done a bit of further testing - and it looks like a
*property* call *is* inlined across assemblies. My previous version was
just calling a method which incremented a counter. Adding a property
for that counter and using helper.Count++; came out over twice as fast
as the method call, which suggests it's being inlined.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
n!
> Having done a bit of testing, it doesn't *appear* that it can - at
least not as far as I can see.

I tested this by creating a helper class with two methods, one with
[MethodImplAttri bute(MethodImpl Options.NoInlin ing)] specified. This I
compiled into a library of its own.
Hi Jon,
I've just tried a similar test, after reading your mail. But I seem
to be getting different results (entirely possible its my fault :).

I created a class inside an assembly with two public properties ["int
Inlined" and "int NotInlined"] and flagging the 'NotInlined' property as you
describe above.
I then wrote a simple test console application referencing the assembly, and
call the Inlined attribute 9999999 times and output the length of time
taken. And the same again but with the 'NotInlined' attribute. The timed
results were:

'Inline' Property: 10.55441ms
'NotInline' Property: 63.79023ms

The only difference between the properties is the 'NoInlining' attribute is
applied to one and not the other. Of course I may still be wrong, and this
is with the 1.0 framework as we're not allowed .NET2003 at work (I can check
with the 1.1 framework when I get home later). Just thought I'd add to your
post, I can mail my test project to anyone interested (maybe I did something
wrong? :).
This is slightly worrying, I must admit...


I will certainly be worried if the JIT can't inline such calls. :/

n!
Nov 15 '05 #5
n!
> I've just done a bit of further testing - and it looks like a
*property* call *is* inlined across assemblies. My previous version was
just calling a method which incremented a counter. Adding a property
for that counter and using helper.Count++; came out over twice as fast
as the method call, which suggests it's being inlined.


Ahh, that's where my difference is. Sorry, ignore my other post!

n!
Nov 15 '05 #6
Thanks for your answer (and you to Jon!) and for going to the trouble
to dummy up a test scenario. I've not read up on the compiler
attributes to prevent method inlining. Thanks for the tip.
I do need to worry about this now because performance is very
important to this application. We would change architecture and/or
component structures to accomodate inline compilation for certain
classes.


For a more insightful look into the JIT, the
microsoft.publi c.dotnet.framew ork.performance newsgroup may get you a more
in-depth and definitive answer.


Yea, I thought so to, but this message sat there all alone for 3 days.
Reposting here gets 2 great replies in hours!

Thanks again guys.
"n!" <nf********@nom ailplease.com> wrote in message news:<O6******* *******@TK2MSFT NGP12.phx.gbl>. ..
If I have another assembly that references this helper libary
assembly, could .NET's JIT compiler inline compile the usage of these
small helper functions?


Although I can't give a definitive answer, I would guess that yes it will
inline across assemblies. I say this as the MSIL is compiled to native
assembly by the JIT so there is really no reason for it not to.

Another reason is patly down to the article:
http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/highperfmanaged apps.asp which lists some of rules used by the JIT when it
is deciding whether to inline a method or not. Whilst the article explicitly
states that not all rules are presented, I would have thought
'cross-assembly' would be a significant rule (though once again, my
viewpoint may differ from the actual authors :).

You're not guaranteed a method is inlined however and the rules may change
in future revisions, so I wouldn't spend whole amounts of time worrying
about whether a method is lined or not until you start running into
performance problems with it :)

For a more insightful look into the JIT, the
microsoft.publi c.dotnet.framew ork.performance newsgroup may get you a more
in-depth and definitive answer.

n!

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
6554
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg. accessor and mutator methods to access private data members). I would like to know if there are any issues with using inline functions that may have attributed to my errors before I start separting them out into "outline functions". Regards
47
3852
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
30
19713
by: Will Pittenger | last post by:
Does C# inline functions? I do not see a inline keyword. Is there an implicit inline? Can the compiler select functions for auto-inlining? I am more used to C++ where all these things are possible. ---------- Will Pittenger E-Mail: mailto:will.pittenger@verizon.net All mail filtered by Qurb (www.qurb.com)
5
1945
by: Ondrej Spanel | last post by:
I though that inline functions should be always visible only in the compilation unit where they are defined - meaning if compiler cannot inline them, they should be handled as if declared static. However sample attached shows VC compiler does not work this way (tested in .NET 2003). When you compile the sample with inlining enabled (like in default Release config), the output is A1 = 1, A2 = 2. When run with inlining disabled (Debug),...
2
1396
by: Jiho Han | last post by:
I was wondering whether it was possible to change the default ASP.NET compilation behavior. I know that there is <compilation> element in the config where you can specify quite a few things including the compiler options, assemblies to link, etc. However, I can't seem to find a way to have the compiler add/use certain path to locate the dlls. I tried setting compilerOptions attribute of the <compiler> element...
14
2103
by: Frederick Gotham | last post by:
The original purpose of "inline" was that code could be "expanded in place". Of course, it has other uses... For one thing, the following two translation units will compile together succesfully into a program: /* source1.cpp */ inline int Func(double arg) {
1
10405
by: Omatase | last post by:
Here is my code: CDO.Message iMessage = new CDO.MessageClass(); string sFrom; string sDate; iMessage.DataSource.Open(bstrURLItem,null, ADODB.ConnectModeEnum.adModeRead, ADODB.RecordCreateOptionsEnum.adFailIfNotExists, ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
5
1916
by: Barry | last post by:
Hi, group First, I write same cases I've already known, I don't concern that specific compiler really do inline or not. Please check them if they are right, and add the cases I miss 1. // a.h inline void f() {}
17
8367
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline the function if possible" (because if the compiler has the function definition available at an instantiation point, it will estimate whether to inline it or not, and do so if it estimates it would be beneficial, completely regardless of whether...
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.