Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Tue Oct 17, 2017 11:14 am

All times are UTC




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Optmization Policy
PostPosted: Sun Sep 05, 2004 6:55 pm 
Offline
Engineer
Engineer

Joined: Fri Jun 25, 2004 3:20 pm
Posts: 76
Location: Enschede, Netherlands
After seeing some patches, I noticed that a lot of people tend to over-optimize here and there.

In particular (the direct cause of this post) is replace this:
Code:
a / 256

by
Code:
a >>  8


The argument is, that bitshifting is a lot faster that dividing. I won't argue with that, because it is. But, I believe that making this optimization makes the code less readable, which is something we should prevent.
Besides that, this optimization is quite trivial and will allways be made by the compiler (I tested, even gcc -O0 does it).

There are probably other optmisations like this, though I can't recall anything from the top of my head right now. To prevent the code becoming even more unreadable because of these things, I propose the following policy:
  • The only kind of optmization that can be applied, is optmization in the algorithms or data structures used. Other optimisations that simply replace one piece of code by another, semantically similar one, should be handled by the compiler. Anything that isn't too complex for you, won't be too complex for the compiler either.
  • If any optmization is applied it should always be commented. No Exceptions.
  • If any optimization is applied, include the original code in comments.
    A hint here is to just code something the way you would want it and when applying optimization, comment out the original and replace it by the optimized code.

What do we think of this?

Matthijs


Top
   
 Post subject:
PostPosted: Mon Sep 06, 2004 9:09 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Apr 18, 2004 8:27 pm
Posts: 1228
It sounds good, but remember quite a few of the patch makers had very little or no knowledge with C before finding this game, and have learnt it to make patches for it. I was one of these people and I didn't even know what bit shifting was until a few weeks ago.

It you could explain how all these optimisations work (or post some links) I think it would be a lot better for people to learn about them.

_________________
No longer active here, but you can still reach me via email: luca[at]stackednotion[dot]com


Top
   
 Post subject:
PostPosted: Mon Sep 06, 2004 10:02 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1628
Location: Netherlands, Enschede
he wants us to NOT do optimizations, so you don't have to learn them ;)

His point is that most of the optimizations that coders apply are done by the compiler too, so you might as well leave the slower but more readable code.

_________________
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.


Top
   
 Post subject:
PostPosted: Mon Sep 06, 2004 10:31 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Feb 24, 2003 6:45 pm
Posts: 3053
Location: Hong Kong
Optimizations are of course important. But senseless optimizations that if you want to divide by 256 you write >>8 instead of /256. Optimizations are important, but keep it sensible :)

If you are unsure if a given optimizations is senseless or not, have a look at the assembly output for a comparison :)

_________________
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2017 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2017.
Hosted by Zernebok Hosting.