473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 2394
ThomasR <tr**********@earthlink.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
[MethodImplAttribute(MethodImplOptions.NoInlining)] 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.com>
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/highperfmanagedapps.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.public.dotnet.framework.performance newsgroup may get you a more
in-depth and definitive answer.

n!
Nov 15 '05 #3
Jon Skeet [C# MVP] <sk***@pobox.com> 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
[MethodImplAttribute(MethodImplOptions.NoInlining)] 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.com>
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
[MethodImplAttribute(MethodImplOptions.NoInlining)] 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.public.dotnet.framework.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********@nomailplease.com> wrote in message news:<O6**************@TK2MSFTNGP12.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/highperfmanagedapps.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.public.dotnet.framework.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
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....
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
30
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...
5
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....
2
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...
14
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...
1
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,...
5
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. //...
17
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.