Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

optimisation

This topic is 2774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

going to be starting my 3rd year project next week , creating a game engine.
we have been told to minimilse optimisation until we make sure that the program is working. but i figure making small optimisations when writing the code would be ok .

i mean small , things like using short instead of ints . by reference etc

i sure it would be best doing that .
any methodology i should follow

Share this post


Link to post
Share on other sites
Advertisement
Do as you have been told. Make the code as clear as possible, use reasonable algorithms, and don't worry about things like using short instead of int. Start with int and only change it if you have a good reason later on.

Passing large objects by const reference instead of by value (I assume that's what you were talking about) is generally a good idea. I wouldn't consider it an optimization.

Share this post


Link to post
Share on other sites
How does using shorts instead of ints optimise anything ?

Memory usage possibly but these days...crikey we've got loads of RAM / disk space.

Get it working first....then optimise later if you have a problem....and ALWAYS profile first and never guess at what to optimise.

Share this post


Link to post
Share on other sites

i mean small , things like using short instead of ints .

This is probably one of the reasons you've been asked not to make optimizations initially. The problem is that in the absence of hard data and/or considerable experience, most guesses you might make about what is and is not an optimization will likely be just that - guesses. Using shorts instead of ints is probably a good example of this. (Is there any particular case you have in mind where you think using shorts would offer an advantage?)

As has been mentioned though, passing non-trivial types by constant reference is standard practice, and is (arguably) as much an idiom as it is an optimization (although efficiency is certainly one of the reasons for it being standard practice).

Share this post


Link to post
Share on other sites
I agree with previous posts, don't optimize straight away.
While designing your architecture you should consider how things can be optimized later on, however this is more about the data structures and algorithms used, rather than the "tiny optimizations".
You're best bet is implementing the core functionality and profiling the code to find bottlenecks later on. There's no point in optimizing something, if it'll have little impact.
As repeatedly stated: "90% of the time is spent in 10% of the code", it's just finding that 10%.

Additionally, there's little harm in reworking the framework during development. I restarted my final year project twice, well, I reworked the core systems like the renderer for batching optimizations etc.

Share this post


Link to post
Share on other sites
Optimizing right away just makes the code less readable and harder to determine where the real flaws lies. The funny thing? When you get around to the end, you still will have to optimize! It's simply that much more efficient to save optimization for last since until that point everything is fluid and in a state of uncertainty; afterwards, you can profile and find any remaining bottlenecks and work on them 'till your hearts content.

Share this post


Link to post
Share on other sites

i mean small , things like using short instead of ints . by reference etc

This is an example of precisely why you should not optimise yet. Using a short as say a for-loop counter instead of an int is actually slower because a modern processor actually has to do more work to deal with values that are smaller than the size of its registers. Also, passing PODs or values that are no bigger than the size of a register by const-reference, will at best be the same speed.

Only optimise after they've taught you how to. The other added benefit is that they probably want to measure your optimsation skills by comparing the before and after. If you make the before too good then your performance improvement later on will be less, making you seem to suck at optimisation.

Share this post


Link to post
Share on other sites

going to be starting my 3rd year project next week , creating a game engine.
we have been told to minimilse optimisation until we make sure that the program is working. but i figure making small optimisations when writing the code would be ok .


You've been told this for a reason. Programs are complex, and by keeping your head above matters of optimization while writing, you can focus on the real goal: Writing a working program; because this is hard enough by itself.

i mean small , things like using short instead of ints . by reference etc[/quote]


You're getting yourself bogged down with little details that don't really matter (not until the later stages of optimization, at least). Micro-optimization "tricks" aren't optimization. They're by and large a waste of time.

i sure it would be best doing that . [/quote]Using references is ok. Nobody told you to willfully write stupid code.


any methodology i should follow[/quote]

K.I.S.S.

Share this post


Link to post
Share on other sites
Using shorts instead of ints is one of those things that seems alright on the surface, but wait until you have a need to store a number higher than 32767 which you hadn't anticipated. This is exactly the kind of thing that can get you bogged down in a maintenance nightmare, especially if some of those shorts have now made it into a binary file format. The exception to this rule is if we're talking about index buffers - on many platforms 16-bit indexes are a better choice.

Your thinking suggests to me that you're pre-empting optimization. Don't do that - optimize when you know that you have a problem, not before. This is all the more true if you're coding to a GPU as well as a CPU - they're different beasts and techniques that work well on one don't necessarily work so well on the other. You may also be in the "less storage == more efficient == faster" mindset. That's almost completely bogus at this kind of fine-grained level; non-native storage formats will almost always be slower than native storage formats as they typically need to be translated to the native format before they can be used.

One final thought. Optimization is frequently a case of saying "the 'official' way that the books teach it is wrong for my use case, I'm going to do it another way instead". In order to be able to say that you need to know what the 'official' way is first though, you need to understand how it works, and you need to understand why it's wrong for your use case. That's the purpose of your course, so focus on that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!