Bukkit/Bukkit — pull request #772 by crast (2013-02-17 00:46:04+00:00)
Title: Create StaticMetadataValue with substantial speed improvements

The original iteration of this (pull request #560) changed inheritance hierarchy, so I re-did this as creating a new base class. See https://bukkit.atlassian.net/browse/BUKKIT-1460 for more explanation as to the reasoning behind this.

This is two commits incoming because this also includes the changes from pull #771 which should be approved first before looking at this one.

To prove this is a worthy of creating a new class, I made a series of performance tests which I have in a separate branch: https://github.com/crast/Bukkit-Work/tree/static-metadata-perf-tests.

Running on my machine (Java SE 7, 64bit, OSX) I was able to get these results:

**Memory Test Results: (1 million objects)**

FixedMetadataValue:
phase1: 154.5 MB
phase2: 198.3 MB

StaticMetadataValue:
phase1: 84.7 MB
phase2: 84.8 MB

**Speed Test Results:**

Testing value FixedMetadataValue: 10000000 iterations
=> Elapsed 1670 ms
Testing value StaticMetadataValue: 10000000 iterations
=> Elapsed 82 ms
(~ 20.3x speedup )

Testing value FixedMetadataValue: 100000000 iterations
=> Elapsed 16783 ms
Testing value StaticMetadataValue: 100000000 iterations
=> Elapsed 841 ms
(~ 20.0x speedup)

As you can see, this uses significantly less memory (almost half), and provides a significant speedup (at the worst I saw a 3x speedup, and at some point it looks like HotSpot optimized it even more to a 20x speedup, while it seems HotSpot couldn't optimize FixedMetadataValue at all).

My recommendation would be to deprecate FixedMetadataValue and encourage people to use StaticMetadataValue (or at least provide a strong explanation in the documentation for FixedMetadataValue)