Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualOlof Hedman

Posted 08 October 2012 - 05:50 AM

That sounds like the worst kind of micro-optimization. If you're worrying about things down to individual bytes and cycles, then you're worrying about the wrong things. There's rarely meaningful performance gains to be had from that kind of optimization. At the same time, if you have a struct with 5 ints but you only use one of them, the big question is - why on earth do you have 5 ints in the struct? If there's no reason for the other 4 to be there - get rid of them. But that's from a good code-cleanliness perspective rather than anything else.


I think they are more referring to a design issue, where those 5 ints in some way are conceptually coupled (they are parameters to a "vehicle" or such), but you in that particular function you want to optimise only use one of them (like for example the "speed"). In that case it might be bad for memory throughput and cache to work on this sparse array.
Still a micro optimisation though, and nothing you should worry about until you find you need it through performance measurements.

It's good to know about these "tricks" or "gems", but one should not confuse them with code guidelines, and should not worry about them in daily work. (unless you are a performance optimisation specialist)

#2Olof Hedman

Posted 08 October 2012 - 05:48 AM

That sounds like the worst kind of micro-optimization. If you're worrying about things down to individual bytes and cycles, then you're worrying about the wrong things. There's rarely meaningful performance gains to be had from that kind of optimization. At the same time, if you have a struct with 5 ints but you only use one of them, the big question is - why on earth do you have 5 ints in the struct? If there's no reason for the other 4 to be there - get rid of them. But that's from a good code-cleanliness perspective rather than anything else.


I think they are more referring to a design issue, where those 5 ints in some way are conceptually coupled (they are parameters to a "vehicle" or such), but you in that particular function you want to optimise only use one of them (like for example the "speed"). In that case it might be bad for memory throughput and cache to work on this sparse array.
Still a micro optimisation though, and nothing you should worry about until you find you need it through performance measurements.

#1Olof Hedman

Posted 08 October 2012 - 05:36 AM

That sounds like the worst kind of micro-optimization. If you're worrying about things down to individual bytes and cycles, then you're worrying about the wrong things. There's rarely meaningful performance gains to be had from that kind of optimization. At the same time, if you have a struct with 5 ints but you only use one of them, the big question is - why on earth do you have 5 ints in the struct? If there's no reason for the other 4 to be there - get rid of them. But that's from a good code-cleanliness perspective rather than anything else.


I think they are more referring to a design issue, where those 5 ints in some way are conceptually coupled (they are parameters to a "vehicle" or such), but you in that particular function you want to optimise only use one of them (like for example the "speed"). In that case it might be bad for memory throughput and cache misses to work on this sparse array.
Still a micro optimisation though, and nothing you should worry about until you find you need it through performance measurements.

PARTNERS