EmilHernvall / tregmine

The tregmine plugins
http://tregmine.info/
BSD 4-Clause "Original" or "Old" License
8 stars 10 forks source link

Memory Efficiency #262

Closed lDiverse closed 10 years ago

lDiverse commented 10 years ago

Going to slowly go through some code and improve some of how its written to try and be more efficient.

In this instance, Pointless variables because its value was only used one, and we don't really need to check if it's a zombie since its only triggered by a zombie - but I kept that in. Probably can remove that to though.

EmilHernvall commented 10 years ago

This won't make any difference in terms of code speed. Java has a JIT compiler that automatically optimizes highly utilized code. If this code is executed enough to become a performance issue, optimizations will be performed on it automatically.

Also, from what I can tell there's not necesarily any difference between the original code and your modified code. I imagine that the compiled byte code will be pretty much the same. If anything, it'll be slower because you're making more method calls, while memory usage won't decrease in any significant manner. The memory in question is only ever allocated during the life time of that method call. It'll be freed as soon as the method returns, and a reference is only four or eight byte a piece either way.

Most importantly, I think that assigning code to variables makes the code more readable (and also tends to obey http://en.wikipedia.org/wiki/Law_of_Demeter better), so I'm not that keen on changes like this. :p