• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Imprecision

Slowdowns / 'Anti-Hotspot'

8 posts in this topic

Hi,

I'm working on my Quad-Tree for a while now, to generate the landcape. I optimized it pretty nicely so its able to produce new quads in 1 - 2ms.
The problem is that C# slows down when there wasn't create a new quad for a while (while means starting from 500ms).
Here an example:

[CODE]Node gen; total 106ms noise 69 vert 11 rest
Node gen; total 2ms noise 1 vert 0 rest 1
Node gen; total 2ms noise 0 vert 0 rest 1
Node gen; total 2ms noise 0 vert 0 rest 1
Node gen; total 3ms noise 0 vert 0 rest 2
Node gen; total 4ms noise 2 vert 0 rest 1
Node gen; total 7ms noise 1 vert 0 rest 6
Node gen; total 4ms noise 2 vert 0 rest 2
Node gen; total 37ms noise 1 vert 0 rest 35
Node gen; total 3ms noise 1 vert 0 rest 1
Node gen; total 19ms noise 17 vert 0 rest 1
Node gen; total 18ms noise 17 vert 0 rest 1
Node gen; total 19ms noise 17 vert 0 rest 1
Node gen; total 19ms noise 17 vert 0 rest 1
Node gen; total 2ms noise 1 vert 0 rest 1
Node gen; total 2ms noise 1 vert 0 rest 1
Node gen; total 22ms noise 16 vert 0 rest 4
Node gen; total 2ms noise 1 vert 0 rest 1
Node gen; total 18ms noise 17 vert 0 rest 1
Node gen; total 19ms noise 17 vert 0 rest 1
Node gen; total 19ms noise 17 vert 0 rest 1
Node gen; total 18ms noise 15 vert 0 rest 2
Node gen; total 19ms noise 17 vert 0 rest 1
Node gen; total 18ms noise 17 vert 0 rest 1
Node gen; total 2ms noise 1 vert 0 rest 1
Node gen; total 18ms noise 16 vert 0 rest 1
Node gen; total 2ms noise 1 vert 0 rest 1
Node gen; total 19ms noise 17 vert 0 rest 1
Node gen; total 2ms noise 0 vert 0 rest 1
Node gen; total 2ms noise 1 vert 0 rest 1[/CODE]

As you can see the time for the generation CAN be very fast, but it slows down for no reason :(
The difficulty of the data to create dosen't change at all.

I know that C# / .NET optimizes parts of code that are 'in heavy use'like the hotspot technology in JVM.
Is there any way to enable it manually? How do you handle it?
0

Share this post


Link to post
Share on other sites
[quote name='Imprecision' timestamp='1348595180' post='4983661']
As you can see the time for the generation CAN be very fast, but it slows down for no reason
[/quote]

There's always a reason. For C#, that reason is usually the garbage collector.
0

Share this post


Link to post
Share on other sites
What you need to diagnose the issues is a [url="http://stackoverflow.com/questions/10644/any-decent-c-sharp-profilers-out-there"]profiler[/url].
0

Share this post


Link to post
Share on other sites
[quote name='Telastyn' timestamp='1348606320' post='4983732']
There's always a reason. For C#, that reason is usually the garbage collector.
[/quote]

Can I avoid this problem by creating nodes in a new thread?

[quote name='Adam_42' timestamp='1348615263' post='4983798']
What you need to diagnose the issues is a [url="http://stackoverflow.com/questions/10644/any-decent-c-sharp-profilers-out-there"]profiler[/url].
[/quote]

Mh... I don't think this is what I need. It's not that I don't understand which parts of code lines are slow, I don't know why the are getting slow by random.
0

Share this post


Link to post
Share on other sites
[quote name='Imprecision' timestamp='1348927955' post='4985055']
[quote name='Telastyn' timestamp='1348606320' post='4983732']
There's always a reason. For C#, that reason is usually the garbage collector.
[/quote]

Can I avoid this problem by creating nodes in a new thread?

[quote name='Adam_42' timestamp='1348615263' post='4983798']
What you need to diagnose the issues is a [url="http://stackoverflow.com/questions/10644/any-decent-c-sharp-profilers-out-there"]profiler[/url].
[/quote]

Mh... I don't think this is what I need. It's not that I don't understand which parts of code lines are slow, I don't know why the are getting slow by random.
[/quote]

This is not random. There is a reason for it, probably a lack of memory.

The profiler will tell you if you have enough memory or not.
0

Share this post


Link to post
Share on other sites
[quote name='Imprecision' timestamp='1348927955' post='4985055']
Can I avoid this problem by creating nodes in a new thread?
[/quote]

No.

Another idea is that the resolution of your timer isn't fine enough to measure the true duration of your work. The large difference depends then on if you happen to catch the timer on the outward or inward swing
0

Share this post


Link to post
Share on other sites
Quadtrees tend to be very computationally expensive, and even worse - tend to do lots of heap allocations in loops. I couldn't tell you without looking at your code, but it may be possible that the problem is the garbage collector. If you wanted to stay using c#, you may be able call the GC class and have it clean up after every node is created.

It's unusual that the garbage collector would block you that badly unless you were doing LOTS of heap allocations that keep the variables alive for periods of time where the garbage collector can't figure out if it should treat the variables as a short-lifespan object or a long-lifespan object.

I suggest you read this article and become more acquainted with the GC. http://msdn.microsoft.com/en-us/library/ms973837.aspx
0

Share this post


Link to post
Share on other sites
I you're using generics (i.e. List<Node>) or any other kind of List inside your QuadTree and adding one node at a time, it is very well worth creating your list with a initial size like this;

List<Node> nodes = new List<Node>(32) rather than use the default of "1". As the list extends .net will double the memory allocation for it each time it reaches the end of its preallocated buffer limit - which takes time. If you initialize it to a reasonable guesstimate of the likely size, .net will allocate the memory once-only during class initialization without the need to allocation incrementally with the attendant memory fragmentation. Of course, you dont want to guess too big, because the memory is actually allocated.

I wouldn't recommend touching the GC at all - it does the job its supposed to do. Many people recommend GC.Collect "to make .net faster" but its often an error; the real problem is in the excessive allocation and reallocation of objects and the fragementation that leads from it. For instance; always consider using a for(int) loop rather than a foreach() within quadtree parsing - foreach() creates and destroys and enumerator object - expensive in the kind of nested looping common in quadtrees, whereas the old fashioned for(int) doesn't.

As recommended by the other posters - you reallly, really need to use a profiler. VS.net has one built in, otherwise Ants is a very good one.
0

Share this post


Link to post
Share on other sites
[quote name='PhillipHamlyn' timestamp='1349423807' post='4987046']
I wouldn't recommend touching the GC at all - it does the job its supposed to do. Many people recommend GC.Collect "to make .net faster" but its often an error; the real problem is in the excessive allocation and reallocation of objects and the fragementation that leads from it. For instance; always consider using a for(int) loop rather than a foreach() within quadtree parsing - foreach() creates and destroys and enumerator object - expensive in the kind of nested looping common in quadtrees, whereas the old fashioned for(int) doesn't.

As recommended by the other posters - you reallly, really need to use a profiler. VS.net has one built in, otherwise Ants is a very good one.
[/quote]

This is especially true in games.

Here in our studio we use C# for multiple titles. We never need to force garbage collection to run.

Almost certainly you are creating unnecessary objects and either leaving them in use or casually throwing them away. That is an area that C++ at least forces you to deal with so you realize when you are doing it, C# makes it very easy to create many unnecessary objects consuming your memory in horrible ways.

When performance suddenly slows, we can usually track it down to a programmer spewing out temporary objects or using weak references. A few moments on the profiler will find the source of these allocations rather quickly.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0