junkdog/artemis-odb — pull request #6 by lopho (2013-09-29 10:14:16+00:00)
Title: small bag perfomance improvements and documentation

The most prominent change would be Bag#clear(). It now creates a new empty array instead of nulling the old one. Creating a new array bulk nulls it by a native call.

I did extended profiling on this (several tests over 10000000 subsequent 65 times Bag#add(Entity) and Bag.clear()), and yielded a 80-100% performance increase in Bag#clear(). As Bag#clear() is being called five times each World#process(). This should give a little boost for every artemis user.

The next thing is how BagIterator handles next(). Running try-catch is expensive, and should only be done when we have to catch something that is out of our control. A simple if-clause to check if the cursor is still within bounds should suffice, and still trows an exception if not. A slight increase in performance around 4-10% in BagIterator#next().

Could not find any other performance hotspots without touching the way bag works in general. (Well, maybe I'll take a look at the memory layout, but that would probably be overkill).

The rest is only formatting fixes (whitespaces, javadoc tags) and a completed documentation of Bag and ImmutableBag.

Please check it out. If there are any problems or suggestions let me know.