x


General Performance Question

Hey guys just wanting to get some info about some small things that may or may not be impacting performances for a game. First off i was wondering it it was more effective to call functions to execute code than to just put the code in the the update function. Pesudo* Code example

void Update()
{
 If (true)
 {
   if (this)
    //Do something
   if (this)
    //Do something
   if (this)
    //Do something
 }
}

as opposed to

void Update()
{
if (true)
 ExecFunc();
}

void ExecFunc()
{
if (this)
        //Do something
       if (this)
        //Do something
       if (this)
        //Do something
}

Also i was wondering if and when a class is too large, example a class with over 600 lines of code, would it be more effiecient to split it into 2 300 line scripts or is it just personal preference, also any general tips for c# programming optimization will be greatly appreciated =D

more ▼

asked Aug 10 '10 at 02:31 AM

unityprogrammer008 gravatar image

unityprogrammer008
31 2 2 4

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Get your code working first, then optimize later if needed. Make code as simple and readable as possible, in order to lessen the chance of bugs. Have as little code running as possible.

more ▼

answered Aug 10 '10 at 03:20 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

Profiler is a great tool here. I usually detect the performance problems when the garbage collector is executed. If it gets launched too many times per second, then there's something I can optimize, typically regarding passing structs as value or creating too many disposable classes on each cycle.

Aug 29 '10 at 09:41 AM Edy
(comments are locked)
10|3000 characters needed characters left

Compilers are quite smart nowdays, even runtime ones.

Less important than how you organise is basically not wasting cpu cycles on things that aren't necessary (doing things too often) and allocating memory on the fly (dynamically calling variables rather than using existing ones).

In response to SpikeX, there's nothing wrong with knowing how the underlying tech of what you're doing works. Only with better understanding of how things work can you improve upon what you make :)

more ▼

answered Aug 29 '10 at 02:33 AM

jtbentley gravatar image

jtbentley
579 3 4 16

(comments are locked)
10|3000 characters needed characters left

None of these issues that you're mentioning are going to affect your gameplay in any way whatsoever. It doesn't matter if you have one class or two, or if you split functions into multiple parts. The difference in performance probably isn't even measurable. Why are you even worrying about these mundane details in the first place?

more ▼

answered Aug 10 '10 at 02:35 AM

qJake gravatar image

qJake
11.6k 43 78 161

im fairly new to programming so i was just wondering if i was doing things the right way because ive seen alot of code split into many functions and hardly anything in the main functions IE Update, so i was just curious if this was a personal preference or for performance optimization

Aug 10 '10 at 02:43 AM unityprogrammer008

It's preference. Like Eric said, get your code running first, and then fix it later.

Aug 10 '10 at 05:27 AM qJake
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x664
x472

asked: Aug 10 '10 at 02:31 AM

Seen: 523 times

Last Updated: Nov 05 '10 at 11:27 PM