[OJB-developers] Performance improvements with Identity objects
Brought to you by:
thma
From: Florian B. <bf...@fl...> - 2002-02-27 11:00:28
|
Hi, while fixing the referential integrity issue in the ODMG layer I found that Identity objects are instantiated over and over again. Instantiating objects is one of the most expensive operations one can do in Java, first it creates a lot overhead when instantiating such classes, then it adds overhead in the garbage collector. Once an Identity object is created, the chances it will change is very little. Why not store the Identity object, once it is created? VirtualProxy and IndirectionHandler already do this, if you create an Identity the content of the stored Identity is copied. If we added such storing capabilities for normal objects to a, lets say, IdentityFactory, in most cases a new instantiation could be avoided. If an Identity object is requested from IdentityFactory, it should first check whether for the given object an Identity exists. If yes in a second step it should be checked if the key values have changed. If yes, create a new Identity (because Identity should be immutable, imho, so they could still be used in HashMaps), if no just return the already existing object. Most critical for design and implementation is in my opinion avoiding memory leaks. But I think this could be handled with WeakReference and friends. Any comments? lG, Florian |