Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: .NET Threading Performance in a Render Loop  (Read 654 times)
Zaknafein
Customers
Community Member
*****
Posts: 2670


WWW
« on: July 24, 2008, 12:58:05 AM »

This probably qualifies as blog spam... but I think some of you may find it interesting.

I just made a performance evaluation of different approaches to loop parallelism in a render loop. By "loop parallelism" I mean splitting a loop operation in two smaller loops, as long as they don't interfere with each other, and run them in two separate threads, then join them until both finish.

It's an interesting optimization because it has 0 implication on the exterior of the threaded function, and the thread is temporary/disposable. So, instant performance boost, no concurrency checks,... what's the catch?

I thought there was a catch, but there isn't. Turns out it's a good idea and you don't have to make your own code to bypass performance issues. The simplest, plain old .NET implementation is the fastest.

http://www.theinstructionlimit.com/?p=49

If you think I should shut up about my blog on the forums, do tell. Cheesy
Logged

zaknafein.
>> the instruction limit : my blog & samples repository! <<
micmanos
Customers
Community Member
*****
Posts: 420

End of this evil world in 4..3..2..


WWW
« Reply #1 on: July 24, 2008, 01:31:26 AM »

THANKS A LOT FOR THIS RESEARCH ZAK ....

I was too absorbed in using threads and between ParameterizedThreadStart and keeping the thread alive, the later seemed more efficient for human logic.

Later i've changed the code so that i can pass context as the threads delegate so i inevitably changed to The former (Param..start).

I didn't took the time to actually benchmark the two so your little (ok, not so little) research, really put my mind at ease !!

Thanks again friend ...

PS: If anyone is in threading, i would strongly suggest taking a good look at the benchmarking table ....
Logged

ownage
Community Member
*
Posts: 17


« Reply #2 on: July 24, 2008, 05:08:19 AM »

very interesting! I looked at the results, and the performance difference is amazing. I will download that sample and test that all out for myself on my pc and see if i can get that 30% speed difference.
Logged
WEst
Community Member
*
Posts: 813

Daniel Martinek


WWW
« Reply #3 on: July 24, 2008, 09:13:19 AM »

I tested it on my system (Athlon 64 X2 4600+), and I'm very impressed with the results, the different Threading Methods are almost equally fast all need almost 50% of the time of single threaded method:
Quote
Test 'Single-Threaded' Started... Completed.
Time Elapsed : 00:00:27.4685282

Test 'Multi-Threaded, ParameterizedThreadStart' Started... Completed.
Time Elapsed : 00:00:14.1143229

Test 'Multi-Threaded, Class-Local Context' Started... Completed.
Time Elapsed : 00:00:14.0368599

Test 'Multi-Threaded, Generic Context' Started... Completed.
Time Elapsed : 00:00:14.0125935

Test 'Multi-Threaded, Kept-Alive Thread' Started... Completed.
Time Elapsed : 00:00:14.6710498

It's good to see, that we can get quite a huge improvement if we use multithreading the right way.
Logged

Greetings

Daniel Martinek
Lead Programmer
Roaming Nova Studios
Lenn
Customers
Community Member
*****
Posts: 454

Ivan Miskelic


« Reply #4 on: July 24, 2008, 09:48:27 AM »

Zak, I'm beginning to think you're some sort of divine spirit, guiding light, sent from another planet to guide me in my quest for completing my project or something! You keep posting answers to questions I'm about to ask in a day or two!! Like last time you did with the terrain shadow mapping shader - just when I needed it.

I was just doing my own reading on the subject, and getting ready to start coding, and yet , here it is. All summed up nicely, exactly for the language I need as well.

You rule! hahahah
Logged

Zaknafein
Customers
Community Member
*****
Posts: 2670


WWW
« Reply #5 on: July 24, 2008, 09:58:54 AM »

Thanks everyone!

@Lenn : Bwhahah, well glad I'm so helpful.

@WEst : Interesting that keeping a thread alive is less costly on your system. Are you using Vista? I know that most threading facilities are calls to the OS, so monitors could be faster in Vista...

Anyway the main point of my research is that keeping a single thread can't be faster. I can only be slower or almost have the same speed.
Logged

zaknafein.
>> the instruction limit : my blog & samples repository! <<
Lenn
Customers
Community Member
*****
Posts: 454

Ivan Miskelic


« Reply #6 on: July 24, 2008, 10:25:30 AM »

You sure are Wink keep it up eh

However, are you sure the results would be the same on older single-core processors? Especialy those without hyperthreading?
Logged

Zaknafein
Customers
Community Member
*****
Posts: 2670


WWW
« Reply #7 on: July 24, 2008, 10:28:57 AM »

Definitely not. This is not a er... past-proof speed boost. My friend was talking about that with me minutes ago, and you definitely can't substitute code optimization with this kind of multi-threading, because you can't assume that everyone will benefit from it.

But the trend is really towards multi-core CPUs, and when doing XNA stuff on the Xbox, you have 6 cores to distribute your work, so I think threading is the future. You just need to do a codepath for those older PCs. Tongue
Logged

zaknafein.
>> the instruction limit : my blog & samples repository! <<
WEst
Community Member
*
Posts: 813

Daniel Martinek


WWW
« Reply #8 on: July 24, 2008, 12:18:20 PM »

Thanks everyone!

@WEst : Interesting that keeping a thread alive is less costly on your system. Are you using Vista? I know that most threading facilities are calls to the OS, so monitors could be faster in Vista...

Yep, I'm using Vista here, so maybe this will explain why they are almost equally fast.
Logged

Greetings

Daniel Martinek
Lead Programmer
Roaming Nova Studios
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks