Adam Heath wrote:
David E Jones wrote:
The more common approach, and what would be even faster than a static
method with an internal cache, is to use a factory method that is
smart enough to see if an object for the given original String already
exists and if so then use it.
This implies that the FlexibleStringExpander is immutable, which I
looked at real quick and it appears to already be.
I was thinking about using the javolution ObjectFactory to do object
recycling (like in GenericDelegator), but that really isn't needed for
an immutable Object pattern like this where the objects retrieved are
kept and reused and not rebuilt each time rather than being thrown
away and recreated frequently.
BTW, the factory method with an actual instance pointed to in the user
objects is faster than the static method doing a lookup in an internal
cache mostly because it saves on the lookup.
Most excellent.
I'm working on changing service engines to cache invocations. Doing a
loadClass, getMethod each time is slow; caching the looked up field is a
significant speedup.
Here's a test. Note how that plain standard reflection, when the Method
lookup is cached in a final instance variable, is *slower* than my own
custom implementation.
The fourth item listed is basically how OfBiz does it's method calls.
Basically, ClassLoader.loadClass(className).getMethod(methodName,
DispatchContext.class, Map.class). Continuously.
I'll be working this into the ServiceEngine over the next few days.
ps: this is the first major speedup work to come from webslinger.
==
ref.ReflectionTest$Normal(500000)=2.539026068
ref.ReflectionTest$Reflection(500000)=3.287744069
ref.ReflectionTest$ContinualReflection(500000)=6.518010998
ref.ReflectionTest$ContinualLoadingReflection(500000)=8.913640043
ref.ReflectionTest$Compiled(500000)=2.871062177
ref.ReflectionTest$Dispatcher(500000)=2.672173324
ref.ReflectionTest$SyncRefLoadingReflection(500000)=3.383238542
ref.ReflectionTest$AtomicRefLoadingReflection(500000)=3.37369552
ref.ReflectionTest$SyncRefLoadingCompiled(500000)=3.041537616
ref.ReflectionTest$AtomicRefLoadingCompiled(500000)=3.027191239
ref.ReflectionTest$SyncRefLoadingDispatcher(500000)=2.784919375
ref.ReflectionTest$AtomicRefLoadingDispatcher(500000)=2.791944651
==