The following code snippet with Joda-Time 2.1 take more than 10 times longer than with Joda-Time 1.5.2.
final long time = System.currentTimeMillis();
final DateTime dt = new DateTime();
for (int i = 0; i < OPERATION_COUNT; i++) {
dt.plusDays(1);
}
System.out.println("treatment in " + (System.currentTimeMillis() - time) + "ms");
Joda-Time 1.5.2: treatment in 169ms
Joda-Time 2.1: treatment in 2995ms
Is this a regression ?
In Joda-Time 2.x I use volatile fields to ensure thread safety (as required by the memory model). That is probably what you are seeing. The only alternative is breaking backwards compatibility on serialization and more.
I see a performance regression as well, but not as much. When I remove the volatile modifiers, performance is restored.
I believe performance of 2.x compared to 1.x in some cases is greatly degraded because of this commit: http://sourceforge.net/p/joda-time/svn/1596/tree//trunk/JodaTime/src/main/java/org/joda/time/DateTimeZone.java?diff=1595 . Volatile modifiers affect performance very little compared to this.