Improving performance of .NET

Started by
17 comments, last by AliasNotFound 19 years, 11 months ago
I did the same thing, with similar results. It turned out that my Vector3 struct didn''t have any of its calls inlined. The .net JIT is fairly conservative in what it inlines. You might want to check that these functions are being inlined, and if not, do the expansion yourself in the time critical areas.

Is your program multithreaded? WaitForSingleObject sounds like it''s the result of synchronized access.

Advertisement
quote:Original post by sjelkjd
I did the same thing, with similar results. It turned out that my Vector3 struct didn''t have any of its calls inlined. The .net JIT is fairly conservative in what it inlines. You might want to check that these functions are being inlined, and if not, do the expansion yourself in the time critical areas.

The JIT can only inline static, non-virtual and operators.

Operators are practically garrentied to be inlined, and non-virtuals are iffy.

quote:Is your program multithreaded? WaitForSingleObject sounds like it''s the result of synchronized access.

This sounds like the biggest hit. Did you use the ''lock'' keyword?

quote:Original post by ggs
quote:Original post by sjelkjd
I did the same thing, with similar results. It turned out that my Vector3 struct didn''t have any of its calls inlined. The .net JIT is fairly conservative in what it inlines. You might want to check that these functions are being inlined, and if not, do the expansion yourself in the time critical areas.

The JIT can only inline static, non-virtual and operators.

Yes, and it won''t inline more than 32 bytes of IL, and tends to give up if non-trivial control logic is present as well. And your statement is not exactly true - it could inline virtual methods in a sealed class if invoked from a variable of that type.
Anyway, the best way to find out is to check the generated assembly code.
quote:Original post by sjelkjd
Yes, and it won't inline more than 32 bytes of IL, and tends to give up if non-trivial control logic is present as well.

I also expect JITed native code isnt shared across process boundaries.

But its early days yet for the .NET framework from Microsoft.

quote:And your statement is not exactly true - it could inline virtual methods in a sealed class if invoked from a variable of that type.

That would because a virtual method in a sealed class is the equivalent of a non-virtual method anyway. Just with an extra level of redirection which never changes.

Under the v2.0(aka next version) of the framework, apparently the JIT can inline virtual function and interface functions as required. Also allows delegates to be upto 50 times faster than the current implementation.

It is no suprise that Microsoft has licensed Sun's java technology(see the recent $1.6 billion settlement between Sun & Microsoft). Since everything is a virtual under java, Sun has put a lot of research into JIT optimizations of virtual methods & interfaces. The license should allow MS access to Sun's research on JIT optimizations.

The .NET JIT is incredibly dumb in its current state, were as JVM JITs are typically fairly smart. And the JVM JITs need to be, since they are working with an architecture which has fundamental performance problems unless you use some clever optimization strategies.



[edited by - ggs on April 12, 2004 7:52:07 AM]
please stay to topic and don''t make this thread a war.
A lot of time inside ArrayListEnumeratorSimple.MoveNext implies you are using foreach which is currently unoptimized.

The addition of the yeild keyword to .NET 2.0 will make foreach faster than regular for loops (because internally it can skip the bounds checking), but until then use for(int i = 0; i < array.Length; i++)
Does anyone know if

Dim i As Integer
Dim what As Type
For i = 0 To x - 1
what = whatArray(i)
''whatever
Next

or

Type what;
for (int i, i{
what = whatArray;
//whatever
}

is faster than?:

Dim i As Type
For Each what In whatArray
''whatever
Next

or C# foreach
DrGUI: See my post right before yours!

Personally, I use foreach in non performance critical code. But in a game engine, you need to advoid allocating a ton of array enumerators. So I use a standard for loop with a //USEFOREACH comment so I can upgrade to a real foreach once C# 2.0 comes out.
I did a little timing demo comparing looping with for-each and an indexer in VB.NET. The app wasn''t complex or wholely scientific...I''m sure there were issues with my method, but the results were pretty consistant.

I tried:
* small lists (10 items)
* large lists (10000 items)
* boxed and non-boxed types (ints, strings, test class)
* Arraylist and CollectionBase

With little variation using the indexer was 2x faster. It may take 30 minutes to create this app for yourself...but it''s a good learning experience. Of course the real trick is to re-run all your test apps once the next version comes out...


Epolevne

This topic is closed to new replies.

Advertisement