Indeed Riven is right (again). Once upon a time loop unrolling in java (and C) was something you did and it would be faster. That was a long time ago. Compilers in C/C++ unroll for you and so does JIT. Even better JIT can unroll using parameters that you don't know at compile time. Things that can be shown not to change are also typically moved out of the loop. JIT can and does often eliminate bounds checks too when it can prove that out of bounds never happens. Even micro benchmarks can show all this.

On top of all that even in the old days you would never unroll all 256 elements of a loop. Perhaps you would unroll 16 or so and loop 16x. But since the compiler/JIT can tune these to the particular loop, its always "better".

I have no special talents. I am only passionately curious.--Albert Einstein

Thing is Java was designed specifically in mind of "make your code look neat and tidy and easy to understand, and we'll worry about making it fast enough". By and large they have achieved this goal admirably. Almost no-one ever has any serious performance problems in Java that are fixable with this sort of micro-optimisation. Except on Android, where sadly stuff like caching .length in a loop comparison is still a valid optimisation.

Thing is Java was designed specifically in mind of "make your code look neat and tidy and easy to understand, and we'll worry about making it fast enough". By and large they have achieved this goal admirably. Almost no-one ever has any serious performance problems in Java that are fixable with this sort of micro-optimisation. Except on Android, where sadly stuff like caching .length in a loop comparison is still a valid optimisation.

Cas

In some pervert way coding against dalvik is fun becouse you have to do every small thing for yourself. Its like c with bad compiler using java syntax.

Masturbation Programming (MP): A common programming technique that involves coming up with a brilliant solution to a problem and then rapidly banging out the code. On completion (assuming it is achieved) then end result is usually an embarrassing mess.

Agile Programming: A software engineering methodology that involve iterative application of the MP technique. Agile developers make impressive claims about their style.

Programming Pairs: MP as a team sport. One partner watching the other generating code, injecting any helpful hints as needed and then later: they trade roles.

... Why are we getting into a discussion about how generalized techniques (such as optimizations and design patterns) are bad anyway? Isn't this thread really the absolute waste of time everyone so valiantly speaks of?

Come on, it is the "stereotypes" of computer science. Everyone gets caught up in them once in their career and just laughs and learns from it afterward. The only time any programming practice is "bad" is when it actually turns into a religious belief.

Optimization 99% of a time is the biggest waste of time you can do on a program. The amount of work to get 1-2 more FPS or even 10 - 15 more bytes of memory is never worth the time. The only time that optimization of code should take place is as a "last resort". In today's age, there is no way we are going to run out of memory, or not have enough speed to perform a simple task.

Personally, design patterns are just a byproduct of trying to make computer science a mindless job. The fact is, we like computer science, but we don't want to code it. If there was a way to translate our thoughts on the computer without typing them down, we'd all flock to it like a bunch of buzzards. I think entity systems, API, and tree node systems all have their place. In no means should we go insane and try to apply them to our code just for the sake of it. Just like you don't use all your wooden blocks to build a castle, some pieces of design should be left out so you can get something built.

... But, yet, here I am wasting my valuable time again. The more time I spend in computer science, the more I believe it is more like Computer Architecture.

Which is exactly the point on both mentioned, optimization & design pattern. Patterns are just snippets that are useful or not and shouldn't replace data-structure, algo & design knowledge. On optimization...real optimization is non-linear and higher level and "premature optimization" is just a single example of wasting one's time and (in my experience) a very unimportant one.

I would like to note that time is a resource and is not infinite. If I have to "optimize" for a week and only get a measly 0.1ms speed in overall average execution time, i'd say that time can be better spent elsewhere.

1) Engineering time is the most valuable resource.2) Optimization is really about attempting to meet a set of goals with some metric for success. Not really those set of things that ideally your language and compiler should ideally be able to do auto-magically do for you. Those are ideally "compiler optimizations". When one is attempting to beat their compiler and/or hold its hand, then best case situations one can only expect very small localized linear time increases and should be avoided unless exactly known to be necessary.3) Performing any task has an associated opportunity cost of twice the amount of time spent performing it.4) On considering speed increases, then the most important are algorithmic and data-structure oriented at the high level. And of these the most important are both non-linear and one that if a "bad" choice is made, then changing to a better option requires significant engineering time. Simple example: attempt to go from an unstructured world to some set of spatial partitioning.5) "premature optimization" is IMHO an oxymoron. This is because "no reasonable goal" is being moved toward. It is simply one example of wasting time. All of which are equally bad.

Is it just me or does everybody have a tattoo to, you know, express their individuality?

I express mine by not having a tattoo

Busy between school, work, life, games, programming and general screwing around.If you'd like some pixel art for your game, send me a PM, i'll see what I can do.Current project: http://elementalwarblog.wordpress.com/

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org