October 18, 2013

Java 8 Method Reference and Lambda Performance

I happened to come across a post on SO talking about performance of methods called via reflection and method handles. I was under the impression that method handles was a Java 8 thing. To my surprise it is actually in Java 7 (I've been coding android for a while so never played much with it). I figure it would be worth while to extend the answers there to show off the performance of some of the Java 8 features. I.e. lambda and method references. It doesn't actually answer the question there so I won't pollute it on SO but I can write it here to show it:

I took the basic code for the micro-benchmark (again micro, does not truly reflect real world performance). A quick dump of my laptop specs (cause people always ask):

Operating System
Windows 7 Ultimate 64-bit SP1
CPU
Intel Core i7 620M @ 2.67GHz 46 °C
Arrandale 32nm Technology
RAM
4.00GB Dual-Channel DDR3 @ 532MHz (7-7-7-20)
Motherboard
LENOVO 2516CTO (None) 53 °C
Graphics
ThinkPad Display 1440x900 (1440x900@60Hz)
DELL P2211H (1920x1080@60Hz)
256MB NVIDIA NVS 3100M (Lenovo)
Hard Drives
298GB HITACHI HTS725032A9A364 ATA Device (SATA) 33 °C
SD Memory Card (NULL)
Optical Drives
Optiarc DVD RW AD-7930H ATA Device
Audio
Conexant 20585 SmartAudio HD

The code I am running is pretty much copy paste from the SO post, but I added a few lines to add in the Java 8 stuff. Anyone familiar with Java will see the new syntax and be in awe at the performance.


And of course here are the results:

reflective invocation (without setAccessible) 4.847 ns
reflective invocation (with setAccessible) 4.593 ns
methodhandle invocation 11.511 ns
static final methodhandle invocation 0.000 ns
direct invocation 0.000 ns
method reference invocation 0.000 ns
lambda invocation 0.000 ns

Which pretty much means the performance is no better than static final methodhandles OR direct invocations... which goes to show how huge of an impact these new constructs will have to functional programming in Java. I am impressed.

October 15, 2013

TerraFirmaCraft and Minecraft Forge

I recently came across a wonder mod called TerraFirmaCraft which has proven to be a fairly amazing rework of survival Minecraft. It adds a huge depth to the game play, and unlike every version of Minecraft since early alpha when I first started to play it actually makes the game harder and removes all the 'mob farming/automation' from the game. I find it pretty amazing because a lot of the new red-stone stuff is 'neat' but it really just makes the easy parts of the game even easier. I wouldn't be able to describe all the changes it has done to the game in a single post (well at least one that people would read) so instead I will simply put it this way: Everything takes more effort, nothing is automated, and you really have to actually work towards your goals. It means when you actually build your first house in TFC it feels like a huge accomplishment because you probably spent a few days trying to gather resources and fighting off significantly more powerful mobs.

This mod has also reminded me of all the parts about Minecraft I really enjoy and how Minecraft Forge allows me to actually tackle some of my mod ideas without trying to dig through Minecraft source (yuck). Needless to say, TFC is still in a beta and has lots of areas to improve. On the other hand, it is very fun and I agree with the premise of the project. As a result, I have decided to contribute my time and effort towards the project to improve it and by writing a couple add-ons for the core mod. My first change has been to revive an older addon which is no longer being maintained called TerraBow. I will likely take the information about it and make an actual page here for people to view. I will also be making posts about other mods I write for TFC and make occasional progress reports (since doing that seems to both tell people I am making progress, and gives me something to refer to).